#include<bits/stdc++.h>
//#define int long long
#define pb push_back
#define fast ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
#define MOD 1000000007
#define INF 1e18
#define fi first
#define se second
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define sz(a) ((int)(a).size())
#define endl '\n'
#define all(a) a.begin(),a.end()
#define pi 3.14159265359
#define TASKNAME "examination"
template<typename T> bool maximize(T &res, const T &val) { if (res < val){ res = val; return true; }; return false; }
template<typename T> bool minimize(T &res, const T &val) { if (res > val){ res = val; return true; }; return false; }
using namespace std;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<int> vi;
typedef pair<ii,ii> iv;
const int MAXN = 1e5 + 9;
const int block = 316;
const int MAXBLOCK = 316;
int n,q,x;
iv score[MAXN], original[MAXN];
int BIT[320][5*MAXN],prep[MAXN],answer[MAXN];
vector<int> listval;
vector<iv> query;
void upd(int block,int id,int x){
for(int i=id;i>0;i-=i&(-i)){
BIT[block][i] += x;
}
}
int get(int block,int id){
int res = 0;
for(int i=id;i<=listval.size();i+=i&(-i)){
res += BIT[block][i];
}
return res;
}
int bs(int l,int r,int x){
int res = -1;
while(l<=r){
int mid = (l+r)>>1;
if (original[mid].se.fi >= x){
res = mid;
r = mid - 1;
}
else l = mid + 1;
}
return res;
}
main()
{
fast;
if (fopen(TASKNAME".inp","r")){
freopen(TASKNAME".inp","r",stdin);
freopen(TASKNAME".out","w",stdout);
}
cin>>n>>q;
for(int i=1;i<=n;i++){
cin>>score[i].se.fi>>score[i].se.se;
score[i].fi.se = score[i].se.fi + score[i].se.se;
listval.pb(score[i].se.fi);
listval.pb(score[i].se.se);
listval.pb(score[i].fi.se);
}
sort(score+1,score+1+n,[](const iv &a,const iv &b){
return a.se.fi < b.se.fi;
});
for(int i=1;i<=q;i++){
int x,y,z;
cin>>x>>y>>z;
listval.pb(x);
listval.pb(y);
listval.pb(z);
query.pb({{i,x},{y,z}});
}
sort(listval.begin(),listval.end());
for(int i=1;i<=max(q,n);i++){
if (i<=n){
score[i].se.fi = lower_bound(all(listval),score[i].se.fi) - listval.begin() + 1;
score[i].se.se = lower_bound(all(listval),score[i].se.se) - listval.begin() + 1;
score[i].fi.se = lower_bound(all(listval),score[i].fi.se) - listval.begin() + 1;
}
if (i<=q){
query[i-1].se.fi = lower_bound(all(listval),query[i-1].se.fi) - listval.begin() + 1;
query[i-1].se.se = lower_bound(all(listval),query[i-1].se.se) - listval.begin() + 1;
query[i-1].fi.se = lower_bound(all(listval),query[i-1].fi.se) - listval.begin() + 1;
}
}
for(int i=1;i<=n;i++){
score[i].fi.fi = i;
original[i] = score[i];
}
sort(query.begin(),query.end(),[](const iv &a,const iv &b){
return a.se.se > b.se.se;
});
sort(score+1,score+1+n,[](const iv &a,const iv &b){
return a.fi.se > b.fi.se;
});
for(int i=1;i<MAXN;i++){
prep[i] = i / block;
// if (i==MAXN-1) cout<<prep[i]<<endl;
}
// for(int i=1;i<=n;i++){
// cout<<score[i].fi.se<<' '<<score[i].se.fi<<' '<<score[i].se.se<<endl;
// }
// cout<<endl;
// for(int i=1;i<=q;i++){
// cout<<query[i-1].fi.se<<' '<<query[i-1].se.fi<<' '<<query[i-1].se.se<<endl;
// }
int ptr = 1;
for(int i=0;i<query.size();i++){
while(ptr <= n and score[ptr].fi.se >= query[i].se.se){
int RealIndex = score[ptr].fi.fi;
int b = prep[RealIndex];
upd(b,score[ptr].se.se,1);
// cout<<i<<' '<<ptr<<' '<<score[ptr].fi.fi<<' '<<b<<endl;
ptr++;
}
int start = bs(1,n,query[i].fi.se);
int b = prep[start];
for(int j=start;j<MAXN;j++){
if (original[j].se.fi >= query[i].fi.se and
original[j].se.se >= query[i].se.fi and
original[j].fi.se >= query[i].se.se){
// cout<<"VALID: "<<original[j].se.fi<<' '<<original[j].se.se<<' '<<original[j].fi.se<<endl;
answer[query[i].fi.fi]++;
}
if (prep[j] != prep[j+1]) {
// cout<<"STOP: "<<j<<endl;
break;
}
}
// cout<<"INFO: "<<start<<' '<<b<<' '<<query[i].fi.fi<<' '<<query[i].fi.se<<endl;
for(int cur=b+1;cur<MAXBLOCK;cur++){
if (cur * block > n) break;
answer[query[i].fi.fi] += get(cur,query[i].se.fi);
}
}
for(int i=1;i<=q;i++){
cout<<answer[i]<<endl;
}
}
Compilation message
examination.cpp: In function 'int get(int, int)':
examination.cpp:38:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
38 | for(int i=id;i<=listval.size();i+=i&(-i)){
| ~^~~~~~~~~~~~~~~~
examination.cpp: At global scope:
examination.cpp:55:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
55 | main()
| ^~~~
examination.cpp: In function 'int main()':
examination.cpp:118:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<int, int>, std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
118 | for(int i=0;i<query.size();i++){
| ~^~~~~~~~~~~~~
examination.cpp:59:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
59 | freopen(TASKNAME".inp","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
examination.cpp:60:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
60 | freopen(TASKNAME".out","w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
6608 KB |
Output is correct |
7 |
Incorrect |
8 ms |
7512 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2228 ms |
509740 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2228 ms |
509740 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
6608 KB |
Output is correct |
7 |
Incorrect |
8 ms |
7512 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |