/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 540.0 KiB
#2 Accepted 1ms 332.0 KiB
#3 Accepted 1ms 540.0 KiB
#4 Accepted 208ms 3.473 MiB
#5 Accepted 1015ms 21.18 MiB
#6 Accepted 403ms 11.617 MiB
#7 Accepted 73ms 900.0 KiB
#8 Accepted 184ms 11.355 MiB
#9 Accepted 225ms 10.855 MiB
#10 Accepted 249ms 11.84 MiB
#11 Accepted 30ms 596.0 KiB
#12 Accepted 56ms 860.0 KiB
#13 Accepted 1ms 540.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]);

        int64_t ans[n + 1] = {};
        for(int i = 1; i <= n; i++)
        {
            int val = ar[i];
            int64_t left1 = pre1.order_of_key(val);
            suf1.erase(--suf1.lower_bound(-val));
            int64_t right1 = suf1.order_of_key(-val);
            ans[i] = 1LL * left1 * right1;
            int64_t left2 = pre2.order_of_key(-val);
            suf2.erase(--suf2.lower_bound(val));
            int64_t right2 = suf2.order_of_key(val);
            pre1.insert(ar[i]), pre2.insert(-ar[i]);
            //dbg(left1, right1, left2, right2);
            ans[i] += 1LL * left2 * right2;
        }
        int q;
        cin >> q;
        while(q--)
        {
            int x;
            cin >> x;
            cout << ans[x] << 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:24:12
Judged At
2024-10-03 16:24:12
Judged By
Score
100
Total Time
1015ms
Peak Memory
21.18 MiB