/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 328.0 KiB
#2 Accepted 2ms 540.0 KiB
#3 Accepted 2ms 492.0 KiB
#4 Accepted 280ms 5.078 MiB
#5 Accepted 660ms 32.531 MiB
#6 Accepted 416ms 17.398 MiB
#7 Accepted 133ms 988.0 KiB
#8 Accepted 283ms 17.008 MiB
#9 Accepted 370ms 16.77 MiB
#10 Accepted 347ms 17.781 MiB
#11 Accepted 42ms 628.0 KiB
#12 Accepted 83ms 680.0 KiB
#13 Accepted 2ms 496.0 KiB

Code

#include<bits/stdc++.h>
using namespace std;

typedef long long int ll;
#define max(a, b) (a < b ? b : a)
#define min(a, b) ((a > b) ? b : a)
#define TEXT freopen("azerah.in","r",stdin); freopen("azerah.out","w",stdout);
#define mod 1000000007
#define pii pair<int,int>
#define F first
#define S second
#define testcase int TT; cin >> TT; for (int tc = 1; tc <= TT; tc++)
#define POL(i,n) for (int i = 0 ; i < n ; ++i)
#define pb push_back
#define all(x) x.begin(),x.end()
//#define endl "\n"
typedef pair<int,int>PL;

//const long long N=1e6+7;
//vector<bool>pre(N,0);
//vector<ll>hp(N,0);
//vector<ll>v;
//ll f=0;
//vector<ll>mak(N,0);
//
//void precomp()
//{
//    pre[0]=pre[1]=false;
//
//    for(ll i=2; i<N; i++)
//    {
//        if(pre[i]==false)
//        {
//            v.pb(i);
//            f++;
//            hp[i]=i;
//            for(ll j=2*i; j<N; j+=i)
//            {
//                pre[j]=true;
//                hp[j]=i;
//            }
//        }
//    }
//
//    ll sum=1,j=1,val=1;
//    while(val<=N)
//    {
//        mak[val]=j;
//        j++;
//        sum*=2;
//        val+=sum;
//    }
//
//}

//ll binpow(ll a,ll b)
//{
//    ll ans=1;
//
//    while(b>0)
//    {
//        if(b&1)
//        {
//           ans=(ans*a);
//        }
//
//        a=(a*a);
//        b>>=1;
//    }
//    return ans;
//}

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

template <typename T> using ordered_set = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T, typename R> using ordered_map = tree<T, R, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

void solve()
{
    ll n,x;
    cin >> n;
    ll a[n+5],mnl[n+5],mxl[n+5],mnr[n+5],mxr[n+5];

    ordered_set<ll>s1,s2;

    for(ll i=1;i<=n;i++)
    {
        cin >> a[i];
        mnl[i]=s1.order_of_key(a[i]);
        mxl[i]=(s1.size()-s1.order_of_key(a[i]+1));
        s1.insert(a[i]);
    }
    for(ll i=n;i>=1;i--)
    {
        mnr[i]=s2.order_of_key(a[i]);
        mxr[i]=(s2.size()-s2.order_of_key(a[i]+1));
        s2.insert(a[i]);
    }

    ll q;
    cin >> q;

    while(q--)
    {
        cin >> x;
        cout << (mnl[x]*mxr[x])+(mxl[x]*mnr[x]) << endl;
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    //TEXT;

    //precomp();


    testcase
    {
        solve();
    }


    return 0;
}

Information

Submit By
Type
Submission
Problem
P1079 Roy and Query (Easy Version)
Language
C++17 (G++ 13.2.0)
Submit At
2024-10-03 18:44:07
Judged At
2024-11-11 02:45:01
Judged By
Score
100
Total Time
660ms
Peak Memory
32.531 MiB