This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define ll long long
#define ld long double
const int N=1e5+50;
struct Query{
int x,y,z,i;
bool operator <(Query a){return z<a.z;}
}Qs[N+50];
vector<int>T[N+50],vals[N+50];
pair<int,int>a[N+50];
int res[N+50];
void update(int qind,int qind1,int qval){
int lb=lower_bound(vals[qind].begin(),vals[qind].end(),qind1)-vals[qind].begin();
for(int i=lb;i<T[qind].size();i+=i&-i) T[qind][i]+=qval;
}
void Update(int qind,int qind1,int qval,bool precalc){
if(precalc){
for(int i=qind;i<=N;i+=i&-i) vals[i].pb(qind1);
}
else{
for(int i=qind;i<=N;i+=i&-i) update(i,qind1,qval);
}
}
int get(int qind,int qval){
int sum=0;
for(int i=T[qind].size()-1;i>=1;i-=i&-i) sum+=T[qind][i];
int lb=lower_bound(vals[qind].begin(),vals[qind].end(),qval)-vals[qind].begin()-1;
printf("|%i %i %i %i\n",qind,qval,lb,sum);
for(auto i:vals[qind]) printf("%i ",i);printf("\n");
for(auto i:T[qind]) printf("%i ",i);printf("\n");
for(int i=lb;i>=1;i-=i&-i) sum-=T[qind][i];
return sum;
}
int Get(int qind,int qval){
int sum=0;
for(int i=qind;i>=1;i-=i&-i){
sum+=get(i,qval);
printf("%i %lld\n",i,sum);
}
return sum;
}
vector<int>Vals;
int Ind(int x){
return upper_bound(Vals.begin(),Vals.end(),x)-Vals.begin()-1;
}
int main(){
int n,q;scanf("%i%i",&n,&q);
for(int i=1;i<=n;i++) scanf("%i%i",&a[i].fi,&a[i].se);
Vals.pb(-1);
for(int i=1;i<=n;i++) Vals.pb(a[i].fi);
sort(Vals.begin(),Vals.end());
Vals.resize(unique(Vals.begin(),Vals.end())-Vals.begin());
for(auto i:Vals) printf("%i ",i);printf("\n");
for(int i=1;i<=n;i++) Update(Ind(a[i].fi),a[i].se,1,true);
for(int i=0;i<=N;i++){
vals[i].pb(0);
sort(vals[i].begin(),vals[i].end());
int m=unique(vals[i].begin(),vals[i].end())-vals[i].begin();
vals[i].resize(m);
for(int j=0;j<m;j++) T[i].pb(0);
if(i<=10){printf("%i: ",i);for(auto j:vals[i]) printf("%i ",j);printf("\n");}
}
for(int i=1;i<=n;i++) Update(a[i].fi,a[i].se,1,false);
sort(a+1,a+n+1,[&](pair<int,int> i,pair<int,int> j){return i.fi+i.se<j.fi+j.se;});
for(int i=1;i<=q;i++){
int x,y,z;scanf("%i%i%i",&x,&y,&z);
Qs[i]={x,y,z,i};
}
sort(Qs+1,Qs+q+1);
for(int i=1;i<=n;i++) printf("%i %i\n",a[i].fi,a[i].se);
for(int i=1;i<=q;i++) printf("%i %i %i\n",Qs[i].x,Qs[i].y,Qs[i].z);
for(int i=1,j=1;j<=q;j++){
while(i<=n && a[i].fi+a[i].se<Qs[j].z){
Update(Ind(a[i].fi),a[i].se,-1,false);
i++;
}
if(j==1) printf("%i\n",Get(3,60));
printf("%i %i\n",i,j);
//res[Qs[j].i]=Get(N,Qs[j].y)-Get(Ind(Qs[j].x-1),Qs[j].y);
//printf("*%i %i %i %i %i %i\n",Ind(Qs[j].x-1),Qs[j].x,Qs[j].y,Qs[j].z,Get(N,Qs[j].y),Get(Ind(Qs[j].x-1),Qs[j].y));
}
for(int i=1;i<=q;i++) printf("%i ",res[i]);
return 0;
}
Compilation message (stderr)
examination.cpp: In function 'void update(int, int, int)':
examination.cpp:18:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
18 | for(int i=lb;i<T[qind].size();i+=i&-i) T[qind][i]+=qval;
| ~^~~~~~~~~~~~~~~
examination.cpp: In function 'int get(int, int)':
examination.cpp:33:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
33 | for(auto i:vals[qind]) printf("%i ",i);printf("\n");
| ^~~
examination.cpp:33:44: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
33 | for(auto i:vals[qind]) printf("%i ",i);printf("\n");
| ^~~~~~
examination.cpp:34:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
34 | for(auto i:T[qind]) printf("%i ",i);printf("\n");
| ^~~
examination.cpp:34:41: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
34 | for(auto i:T[qind]) printf("%i ",i);printf("\n");
| ^~~~~~
examination.cpp: In function 'int Get(int, int)':
examination.cpp:42:23: warning: format '%lld' expects argument of type 'long long int', but argument 3 has type 'int' [-Wformat=]
42 | printf("%i %lld\n",i,sum);
| ~~~^ ~~~
| | |
| | int
| long long int
| %d
examination.cpp: In function 'int main()':
examination.cpp:57:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
57 | for(auto i:Vals) printf("%i ",i);printf("\n");
| ^~~
examination.cpp:57:38: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
57 | for(auto i:Vals) printf("%i ",i);printf("\n");
| ^~~~~~
examination.cpp:51:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
51 | int n,q;scanf("%i%i",&n,&q);
| ~~~~~^~~~~~~~~~~~~~
examination.cpp:52:32: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
52 | for(int i=1;i<=n;i++) scanf("%i%i",&a[i].fi,&a[i].se);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
examination.cpp:70:24: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
70 | int x,y,z;scanf("%i%i%i",&x,&y,&z);
| ~~~~~^~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |