/ SeriousOJ /

Record Detail

Runtime Error


  
# Status Time Cost Memory Cost
#1 Accepted 18ms 18.812 MiB
#2 Runtime Error free(): invalid size 17ms 18.797 MiB
#3 Runtime Error munmap_chunk(): invalid pointer 17ms 18.746 MiB

Code

#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long int
#define endl '\n'
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds; // find_by_order, order_of_key
#define all(v) v.begin(), v.end()
#define pb push_back //
#define mp make_pair
#define fi first                         //
#define se second                        //
#define yes cout << "YES" << endl        //
#define no cout << "NO" << endl          //
#define M 1000000007                     // 1e9+7
#define gcd(a, b) __gcd(a, b)            //
#define lcm(a, b) a *b / gcd(a, b)       //
#define memz(a) memset(a, 0, sizeof(a))  //
#define memn(a) memset(a, -1, sizeof(a)) //
const ll N=2e5+100;
ll arr[N];
vector<ll>segtree[4*N];
void build(ll node ,ll start,ll end)
{
    if(start==end)
    {
        segtree[node].push_back(arr[start]);
        return;
    }
    ll mid=(start+end)/2;
    build(node*2,start,mid);
    build(node*2+1,mid+1,end);
    segtree[node].resize(end-start+1);
    merge(all(segtree[node*2]),all(segtree[node*2+1]),segtree[node].begin());
    return;
}
ll bigquery(ll node,ll start,ll end,ll l,ll r,ll val)
{
    if(start>r||end<l)return 0;
    if(start>=l&&end<=r)
    {
        return segtree[node].end()- upper_bound(all(segtree[node]),val);
    }
    ll mid=(start+end)/2;
    return bigquery(node*2,start,mid,l,r,val)+bigquery(node*2+1,mid+1,end,l,r,val);
}
ll smallquery(ll node,ll start,ll end,ll l,ll r,ll val)
{
    if(start>r||end<l)return 0;
    if(start>=l&&end<=r)
    {
        return lower_bound(all(segtree[node]),val)-segtree[node].begin();
    }
    ll mid=(start+end)/2;
    return smallquery(node*2,start,mid,l,r,val)+smallquery(node*2+2,mid+1,end,l,r,val);
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll tst;
    cin>>tst;
    for(ll test=1;test<=tst;test++)
    {
        //cout<<"Case "<<test<<": ";
        ll n;
        cin>>n;
        for(int i=1;i<=n;i++)cin>>arr[i];
        build(1,1,n);
        ll q;
        cin>>q;
        while(q--)
        {
            ll t;
            cin>>t;
            cout<<bigquery(1,1,n,1,t-1,arr[t])*smallquery(1,1,n,t+1,n,arr[t])+smallquery(1,1,n,1,t-1,arr[t])*bigquery(1,1,n,t+1,n,arr[t])<<endl;
        }

    }
}

Information

Submit By
Type
Submission
Problem
P1079 Roy and Query (Easy Version)
Language
C++17 (G++ 13.2.0)
Submit At
2024-10-05 06:58:55
Judged At
2024-11-11 02:40:28
Judged By
Score
4
Total Time
18ms
Peak Memory
18.812 MiB