/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 324.0 KiB
#2 Accepted 1ms 348.0 KiB
#3 Accepted 2ms 532.0 KiB
#4 Accepted 199ms 4.77 MiB
#5 Accepted 374ms 31.07 MiB
#6 Accepted 302ms 16.77 MiB
#7 Accepted 115ms 788.0 KiB
#8 Accepted 255ms 16.133 MiB
#9 Accepted 328ms 15.809 MiB
#10 Accepted 350ms 17.02 MiB
#11 Accepted 42ms 580.0 KiB
#12 Accepted 81ms 436.0 KiB
#13 Accepted 1ms 532.0 KiB

Code

#include<bits/stdc++.h>
using namespace std;
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define prime_number[21]={11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97}
///POLICY BASED DATA STRUCTURE..
///order_of_key return number of element which are strictly greater/smaller than x..
///find_by_order return ans iterator corresponding to the xth position of the set..
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace __gnu_pbds;
#define ll long long int
#define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update>
#define faster_bro ios_base::sync_with_stdio(false);cin.tie(NULL)
#define esp 0.0000000001
#define ss second
#define ff first
#define nl cout<<endl
//memset(ar,-1,sizeof(ar));
// (1LL<<i) more than efficient pow(2,i);
void fast(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}

int main(){
    fast();
    int tc;
    cin>>tc;
    int h=1;
    while(tc--){
        ll a,b,c,sum=0,sum1=0,sum2=0,cnt=0,mx=LLONG_MIN,mn=LLONG_MAX,mx1=-1e18,mx2=-1e18;
        cin>>a;
        ll ar[a+1];
        ordered_set st,st1;
       for(int i=1;i<=a;i++){

       cin>>ar[i];
       // st.insert(ar[i]);
       }
       int choto_before[a+1],boro_before[a+1],choto_after[a+1],boro_after[a+1];
       for(int i=1;i<=a;i++){
           choto_before[i]=st.order_of_key(ar[i]);
           int choto=st.order_of_key(ar[i]+1);
           boro_before[i]=(i-1)-choto;
          st.insert(ar[i]);
       }
       int j=1;
          for(int i=a;i>=1;i--){
           choto_after[i]=st1.order_of_key(ar[i]);
           //cout<<choto_after[i]<<" ";
           int choto=st1.order_of_key(ar[i]+1);
           boro_after[i]=(j-1)-choto;
          st1.insert(ar[i]);
          j++;
       }

       ll lagbe[a+1];
       for(int i=1;i<=a;i++){
           // cout<<i<<" "<<choto_before[i]<<" "<<boro_after[i]<<" "<<choto_after[i]<<" "<<boro_before[i]<<endl;
        ll k1=1LL*choto_before[i]*boro_after[i];

        ll k2=1LL*choto_after[i]*boro_before[i];

        lagbe[i]=k1+k2;


       }

       int q;
       cin>>q;
       while(q--){
        int x;
        cin>>x;
        cout<<lagbe[x]<<endl;
       }


    }
}

Information

Submit By
Type
Submission
Problem
P1079 Roy and Query (Easy Version)
Language
C++17 (G++ 13.2.0)
Submit At
2024-10-03 22:18:42
Judged At
2024-10-03 22:18:42
Judged By
Score
100
Total Time
374ms
Peak Memory
31.07 MiB