/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 560.0 KiB
#2 Accepted 2ms 520.0 KiB
#3 Accepted 2ms 500.0 KiB
#4 Accepted 307ms 3.555 MiB
#5 Accepted 1547ms 21.195 MiB
#6 Accepted 764ms 11.785 MiB
#7 Accepted 118ms 952.0 KiB
#8 Accepted 279ms 11.305 MiB
#9 Accepted 370ms 11.051 MiB
#10 Accepted 373ms 12.004 MiB
#11 Accepted 45ms 624.0 KiB
#12 Accepted 92ms 880.0 KiB
#13 Accepted 2ms 332.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-11-11 02:48:32
Judged By
Score
100
Total Time
1547ms
Peak Memory
21.195 MiB