/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Wrong Answer 2ms 320.0 KiB
#3 Wrong Answer 3ms 504.0 KiB

Code

#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define dbg(a,b,c,d) cerr<<a<<"  "<<b<<"  "<<c<<"  "<<d<<endl;
#define kill(a) {cout<<a<<endl;continue;}
#define KILL(a) {cout<<a<<endl;return 0;}
#define debug cerr<<"Error Found"<<endl;
#define mem(a,b) memset(a,b,sizeof(a))
#define lcm(a, b) (a/__gcd(a,b))*b
#define w(t) cin>>t;while(t--)
#define pi  2 * acos(0.0)
#define endl "\n"
int t, cs = 0;
const int mxn = 1e5 + 2,mod = 1e9 + 7;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
signed main()
{

    //fast;
    w(t)
    {
        int n;
        cin >> n;
        int ar[n + 1];
        ordered_set pre1, pre2, suf1, suf2;
        for(int i = 1; i <= n; i++)cin >> ar[i], suf1.insert(-ar[i]), suf2.insert(ar[i]);

        int ans[n + 1] = {};
        for(int i = 1; i <= n; i++)
        {
            int val = ar[i];
            int left1 = pre1.order_of_key(val);
            suf1.erase(--suf1.lower_bound(-val));
            int right1 = suf1.order_of_key(-val);
            ans[i] = min(left1, right1);
            int left2 = pre2.order_of_key(-val);
            suf2.erase(--suf2.lower_bound(val));
            int right2 = suf2.order_of_key(val);
            pre1.insert(ar[i]), pre2.insert(-ar[i]);
            dbg(left1, right1, left2, right2);
            ans[i] += min(left2, right2);
        }
        int q;
        cin >> q;
        vector<int>v;
        while(q--)
        {
            int x;
            cin >> x;
            v.push_back(ans[x]);
        }
        for(auto i:v)cout << i << endl;
    }
}

Information

Submit By
Type
Submission
Problem
P1079 Roy and Query (Easy Version)
Contest
Brain Booster #6
Language
C++17 (G++ 13.2.0)
Submit At
2024-10-03 16:18:32
Judged At
2024-12-17 11:35:02
Judged By
Score
4
Total Time
3ms
Peak Memory
532.0 KiB