#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef stack<int> si;
typedef queue<int> qi;
typedef deque<int> di;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
#define endl '\n'
#define pb push_back
#define FOR(i,a,b) for(int i = a; i <= b; i++)
#define BACK(i,a,b) for(int i = a; i >= b; i--)
#define fastIO ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define fi first
#define se second
#define gcd __gcd
#define setmin(x,y) x=min((x),(y))
#define setmax(x,y) x=max((x),(y))
const int MAXN=1e5+5;
const long long inf=1e18;
const int MOD=1e9+7;
struct query
{
int x,y,z,idx;
query(const int& x,const int& y,const int& z,const int& idx):x(x),y(y),z(z),idx(idx){}
bool operator <(const query& other) {return z>other.z;}
};
struct stud
{
int s,t;
stud(const int& s,const int& t):s(s),t(t){}
bool operator <(const stud& other) {return s+t>other.s+other.t;}
};
vector<query> q;
vector<stud> st;
int n,m,ans[MAXN];
vector<int> xs,ys;
vector<vector<int>> node,bit;
void fakeupd(int x,int y)
{
for(;x<=xs.size();x+=x&-x) node[x].pb(y);
}
void fakeget(int x,int y)
{
for(;x>0;x-=x&-x) node[x].pb(y);
}
void upd(int x,int yy)
{
for(;x<=xs.size();x+=x&-x) for(int y=lower_bound(node[x].begin(),node[x].end(),yy)-node[x].begin()+1;y<=node[x].size();y+=y&-y) bit[x][y-1]++;
}
int get(int x,int yy)
{
int res=0;
for(;x>0;x-=x&-x) for(int y=upper_bound(node[x].begin(),node[x].end(),yy)-node[x].begin();y>0;y-=y&-y) res+=bit[x][y-1];
return res;
}
int xid(const int& x)
{
return lower_bound(xs.begin(),xs.end(),x,greater<int>())-xs.begin();
}
int yid(const int& y)
{
return lower_bound(ys.begin(),ys.end(),y,greater<int>())-ys.begin();
}
signed main()
{
fastIO
// freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
cin>>n>>m;
FOR(i,0,n-1) {int s,t; cin>>s>>t; st.emplace_back(s,t); xs.pb(s); ys.pb(t);}
FOR(i,0,m-1) {int x,y,z; cin>>x>>y>>z; q.emplace_back(x,y,z,i); xs.pb(x); ys.pb(y);}
sort(xs.begin(),xs.end(),greater<int>());
xs.erase(unique(xs.begin(),xs.end()),xs.end());
sort(ys.begin(),ys.end(),greater<int>());
ys.erase(unique(ys.begin(),ys.end()),ys.end());
node.resize(xs.size()+1);
bit.resize(xs.size()+1);
FOR(i,0,n-1) fakeupd(xid(st[i].s)+1,yid(st[i].t));
FOR(i,1,xs.size())
{
sort(node[i].begin(),node[i].end());
node[i].erase(unique(node[i].begin(),node[i].end()),node[i].end());
bit[i].resize(node[i].size());
}
sort(st.begin(),st.end()); sort(q.begin(),q.end());
int cur=0;
FOR(i,0,m-1)
{
while(cur<n&&st[cur].s+st[cur].t>=q[i].z) {upd(xid(st[cur].s)+1,yid(st[cur].t)); cur++;}
ans[q[i].idx]=get(xid(q[i].x)+1,yid(q[i].y));
}
FOR(i,0,m-1) cout<<ans[i]<<endl;
}
Compilation message
examination.cpp: In function 'void fakeupd(long long int, long long int)':
examination.cpp:53:8: 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]
53 | for(;x<=xs.size();x+=x&-x) node[x].pb(y);
| ~^~~~~~~~~~~
examination.cpp: In function 'void upd(long long int, long long int)':
examination.cpp:63:8: 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]
63 | for(;x<=xs.size();x+=x&-x) for(int y=lower_bound(node[x].begin(),node[x].end(),yy)-node[x].begin()+1;y<=node[x].size();y+=y&-y) bit[x][y-1]++;
| ~^~~~~~~~~~~
examination.cpp:63:104: 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]
63 | for(;x<=xs.size();x+=x&-x) for(int y=lower_bound(node[x].begin(),node[x].end(),yy)-node[x].begin()+1;y<=node[x].size();y+=y&-y) bit[x][y-1]++;
| ~^~~~~~~~~~~~~~~~
examination.cpp: In function 'int main()':
examination.cpp:18:37: 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]
18 | #define FOR(i,a,b) for(int i = a; i <= b; i++)
......
98 | FOR(i,1,xs.size())
| ~~~~~~~~~~~~~
examination.cpp:98:2: note: in expansion of macro 'FOR'
98 | FOR(i,1,xs.size())
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
8 ms |
1372 KB |
Output is correct |
8 |
Correct |
7 ms |
1400 KB |
Output is correct |
9 |
Correct |
10 ms |
1412 KB |
Output is correct |
10 |
Correct |
5 ms |
1372 KB |
Output is correct |
11 |
Correct |
4 ms |
860 KB |
Output is correct |
12 |
Correct |
2 ms |
860 KB |
Output is correct |
13 |
Correct |
7 ms |
1372 KB |
Output is correct |
14 |
Correct |
6 ms |
1372 KB |
Output is correct |
15 |
Correct |
7 ms |
1580 KB |
Output is correct |
16 |
Correct |
4 ms |
860 KB |
Output is correct |
17 |
Correct |
4 ms |
1372 KB |
Output is correct |
18 |
Correct |
1 ms |
860 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
367 ms |
32956 KB |
Output is correct |
2 |
Correct |
363 ms |
32444 KB |
Output is correct |
3 |
Correct |
372 ms |
32964 KB |
Output is correct |
4 |
Correct |
161 ms |
27840 KB |
Output is correct |
5 |
Correct |
156 ms |
13760 KB |
Output is correct |
6 |
Correct |
62 ms |
12732 KB |
Output is correct |
7 |
Correct |
372 ms |
30396 KB |
Output is correct |
8 |
Correct |
343 ms |
33168 KB |
Output is correct |
9 |
Correct |
368 ms |
30476 KB |
Output is correct |
10 |
Correct |
98 ms |
12120 KB |
Output is correct |
11 |
Correct |
133 ms |
27916 KB |
Output is correct |
12 |
Correct |
55 ms |
11456 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
367 ms |
32956 KB |
Output is correct |
2 |
Correct |
363 ms |
32444 KB |
Output is correct |
3 |
Correct |
372 ms |
32964 KB |
Output is correct |
4 |
Correct |
161 ms |
27840 KB |
Output is correct |
5 |
Correct |
156 ms |
13760 KB |
Output is correct |
6 |
Correct |
62 ms |
12732 KB |
Output is correct |
7 |
Correct |
372 ms |
30396 KB |
Output is correct |
8 |
Correct |
343 ms |
33168 KB |
Output is correct |
9 |
Correct |
368 ms |
30476 KB |
Output is correct |
10 |
Correct |
98 ms |
12120 KB |
Output is correct |
11 |
Correct |
133 ms |
27916 KB |
Output is correct |
12 |
Correct |
55 ms |
11456 KB |
Output is correct |
13 |
Correct |
404 ms |
32620 KB |
Output is correct |
14 |
Correct |
400 ms |
32704 KB |
Output is correct |
15 |
Correct |
423 ms |
32704 KB |
Output is correct |
16 |
Correct |
188 ms |
28352 KB |
Output is correct |
17 |
Correct |
150 ms |
14852 KB |
Output is correct |
18 |
Correct |
63 ms |
13504 KB |
Output is correct |
19 |
Correct |
427 ms |
33112 KB |
Output is correct |
20 |
Correct |
401 ms |
33472 KB |
Output is correct |
21 |
Correct |
398 ms |
32192 KB |
Output is correct |
22 |
Correct |
102 ms |
11960 KB |
Output is correct |
23 |
Correct |
136 ms |
27076 KB |
Output is correct |
24 |
Correct |
41 ms |
12276 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
8 ms |
1372 KB |
Output is correct |
8 |
Correct |
7 ms |
1400 KB |
Output is correct |
9 |
Correct |
10 ms |
1412 KB |
Output is correct |
10 |
Correct |
5 ms |
1372 KB |
Output is correct |
11 |
Correct |
4 ms |
860 KB |
Output is correct |
12 |
Correct |
2 ms |
860 KB |
Output is correct |
13 |
Correct |
7 ms |
1372 KB |
Output is correct |
14 |
Correct |
6 ms |
1372 KB |
Output is correct |
15 |
Correct |
7 ms |
1580 KB |
Output is correct |
16 |
Correct |
4 ms |
860 KB |
Output is correct |
17 |
Correct |
4 ms |
1372 KB |
Output is correct |
18 |
Correct |
1 ms |
860 KB |
Output is correct |
19 |
Correct |
367 ms |
32956 KB |
Output is correct |
20 |
Correct |
363 ms |
32444 KB |
Output is correct |
21 |
Correct |
372 ms |
32964 KB |
Output is correct |
22 |
Correct |
161 ms |
27840 KB |
Output is correct |
23 |
Correct |
156 ms |
13760 KB |
Output is correct |
24 |
Correct |
62 ms |
12732 KB |
Output is correct |
25 |
Correct |
372 ms |
30396 KB |
Output is correct |
26 |
Correct |
343 ms |
33168 KB |
Output is correct |
27 |
Correct |
368 ms |
30476 KB |
Output is correct |
28 |
Correct |
98 ms |
12120 KB |
Output is correct |
29 |
Correct |
133 ms |
27916 KB |
Output is correct |
30 |
Correct |
55 ms |
11456 KB |
Output is correct |
31 |
Correct |
404 ms |
32620 KB |
Output is correct |
32 |
Correct |
400 ms |
32704 KB |
Output is correct |
33 |
Correct |
423 ms |
32704 KB |
Output is correct |
34 |
Correct |
188 ms |
28352 KB |
Output is correct |
35 |
Correct |
150 ms |
14852 KB |
Output is correct |
36 |
Correct |
63 ms |
13504 KB |
Output is correct |
37 |
Correct |
427 ms |
33112 KB |
Output is correct |
38 |
Correct |
401 ms |
33472 KB |
Output is correct |
39 |
Correct |
398 ms |
32192 KB |
Output is correct |
40 |
Correct |
102 ms |
11960 KB |
Output is correct |
41 |
Correct |
136 ms |
27076 KB |
Output is correct |
42 |
Correct |
41 ms |
12276 KB |
Output is correct |
43 |
Correct |
473 ms |
40896 KB |
Output is correct |
44 |
Correct |
458 ms |
41152 KB |
Output is correct |
45 |
Correct |
486 ms |
41408 KB |
Output is correct |
46 |
Correct |
213 ms |
36372 KB |
Output is correct |
47 |
Correct |
161 ms |
14268 KB |
Output is correct |
48 |
Correct |
61 ms |
12736 KB |
Output is correct |
49 |
Correct |
437 ms |
39872 KB |
Output is correct |
50 |
Correct |
428 ms |
41944 KB |
Output is correct |
51 |
Correct |
392 ms |
40124 KB |
Output is correct |
52 |
Correct |
118 ms |
12500 KB |
Output is correct |
53 |
Correct |
152 ms |
35496 KB |
Output is correct |