#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
mt19937 mrand(random_device{}());
const ll mod=1000000007;
const ll mod2=998244353;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head
const int N=301000;
int n,q,s[N],t[N],x[N],y[N],z[N],ans[N];
int p[N],qs[N];
set<int> c[N];
void modify(int x,int y) {
for (;x;x-=(x&-x)) c[x].insert(y);
}
int get(int x,int y) {
int res=0;
for (;x<N;x+=(x&-x)) {
auto it=c[x].lower_bound(y);
res+=(int)(distance(it,c[x].end()));
}
return res;
}
int main() {
VI v;
scanf("%d%d",&n,&q);
rep(i,1,n+1) scanf("%d%d",s+i,t+i),p[i]=i,v.pb(s[i]);
rep(i,1,q+1) scanf("%d%d%d",x+i,y+i,z+i),qs[i]=i,v.pb(x[i]);
sort(p+1,p+n+1,[&](int i,int j) { return s[i]+t[i]>s[j]+t[j]; });
sort(qs+1,qs+q+1,[&](int i,int j) { return z[i]>z[j]; });
sort(all(v)); v.erase(unique(all(v)),v.end());
map<int,int> val;
rep(i,0,SZ(v)) val[v[i]]=i+1;
int ptr=1;
rep(i,1,q+1) {
while (ptr<=n&&s[p[ptr]]+t[p[ptr]]>=z[qs[i]]) {
modify(val[s[ptr]],t[ptr]); ptr++;
}
ans[qs[i]]=get(val[x[i]],y[i]);
}
rep(i,1,q+1) printf("%d\n",ans[i]);
}
Compilation message
examination.cpp: In function 'int main()':
examination.cpp:43:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
43 | scanf("%d%d",&n,&q);
| ~~~~~^~~~~~~~~~~~~~
examination.cpp:44:20: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
44 | rep(i,1,n+1) scanf("%d%d",s+i,t+i),p[i]=i,v.pb(s[i]);
| ~~~~~^~~~~~~~~~~~~~~~
examination.cpp:45:20: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
45 | rep(i,1,q+1) scanf("%d%d%d",x+i,y+i,z+i),qs[i]=i,v.pb(x[i]);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
6 ms |
14412 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3073 ms |
61288 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3073 ms |
61288 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
6 ms |
14412 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |