Submission #921482

# Submission time Handle Problem Language Result Execution time Memory
921482 2024-02-04T01:51:22 Z 1075508020060209tc Examination (JOI19_examination) C++14
0 / 100
442 ms 24028 KB
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define X first
#define Y second
#define SZ(x) (int)(x).size()
int lowbit(int x){return x&-x;}
int bit[1000006];
void upd(int pl,int x){
while(pl<=1000000){
    bit[pl]+=x;
    pl+=lowbit(pl);
}
}
int qsum(int pl){
int ret=0;
while(pl>=1){
    ret+=bit[pl];
    pl-=lowbit(pl);
}
return ret;
}
int n;int Q;
int ar[200005];int br[200005];int cr[200005];
int idar[200005];
int tar[200005];
void lisanhua(){
vector<int>vc;
for(int i=1;i<=n+Q;i++){
    vc.push_back(ar[i]);
    vc.push_back(br[i]);
    vc.push_back(cr[i]);
}
sort(vc.begin(),vc.end());
int it=2;
map<int,int>mp;
mp[vc[0]]=it;
for(int i=1;i<vc.size();i++){
    if(vc[i]!=vc[i-1]){
        mp[vc[i]]=++it;
    }
}
for(int i=1;i<=n+Q;i++){
    ar[i]=mp[ar[i]];
    br[i]=mp[br[i]];
    cr[i]=mp[cr[i]];
}
}


bool cmp(int i,int j){
if(ar[i]<ar[j]){return 1;}
if(ar[i]>ar[j]){return 0;}
return j<i;
}
int ans[200005];
void cdq(int l,int r){
if(l==r){return;}
int mi=(l+r)/2;
cdq(l,mi);cdq(mi+1,r);
int rit=r;
int lit=mi;
vector<int>vc;
for(int i=r;i>=l;i--){
    if( (lit<l)||(rit>=mi+1&&br[idar[rit]]>br[idar[lit]]) ){
        tar[i]=idar[rit--];
        if(tar[i]<=n){
            upd(cr[tar[i]],1);
            vc.push_back(cr[tar[i]]);
        }
    }else{
        tar[i]=idar[lit--];
        ans[tar[i]]+=qsum(1000000)-qsum(cr[tar[i]]);
    }
}

for(int i=0;i<vc.size();i++){
    upd(vc[i],-1);
}

for(int i=l;i<=r;i++){
    idar[i]=tar[i];
}
}


signed main(){

cin>>n>>Q;
for(int i=1;i<=n;i++){
    cin>>ar[i]>>br[i];
    cr[i]=ar[i]+br[i];
}
for(int i=1;i<=Q;i++){
    cin>>ar[i+n]>>br[i+n]>>cr[i+n];
    ar[i+n]--;
    br[i+n]--;
    cr[i+n]--;
}
lisanhua();
for(int i=1;i<=n+Q;i++){
    idar[i]=i;
}

sort(idar+1,idar+n+Q+1,cmp);
cdq(1,n+Q);
for(int i=n+1;i<=n+Q;i++){
    cout<<ans[i]<<"\n";
}return 0;
for(int i=1;i<=n+Q;i++){
    cout<<idar[i]<<" ";
}

}

Compilation message

examination.cpp: In function 'void lisanhua()':
examination.cpp:39:14: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 | for(int i=1;i<vc.size();i++){
      |             ~^~~~~~~~~~
examination.cpp: In function 'void cdq(long long int, long long int)':
examination.cpp:78:14: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   78 | for(int i=0;i<vc.size();i++){
      |             ~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 12636 KB Output is correct
2 Correct 2 ms 12632 KB Output is correct
3 Incorrect 2 ms 12636 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 442 ms 24028 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 442 ms 24028 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 12636 KB Output is correct
2 Correct 2 ms 12632 KB Output is correct
3 Incorrect 2 ms 12636 KB Output isn't correct
4 Halted 0 ms 0 KB -