#include<bits/stdc++.h>
#define pb push_back
#define ii pair<int,int>
#define all(x) (x).begin(),(x).end()
#define INF 100000000000000000
#define modulo 1000000007
#define mod 998244353
//#define int long long int
using namespace std;
struct Person{
int M,I,Z,ind;
bool Q;
Person(int m,int i,int z,int in){
M=m;
I=i;
Z=z;
ind=in;
}
bool operator<(const Person& A)const{
return M<A.M||(M==A.M&&I<A.I);
}
};
vector<Person>arr;
vector<Person>Q;
vector<int>no;
vector<vector<ii>> data;
int sq;
int sz;
bool sort_by_Z(int A,int B){
return arr[A].Z<arr[B].Z;
}
bool Sort_by_Z(int A,int B){
return Q[A].Z<Q[B].Z;
}
int query(vector<ii>& data,int x){
int l=0,r=data.size()-1;
int j=data.size();
while(l<=r){
int mid=(l+r)/2;
if(data[mid].first<x)l=mid+1;
else{
r=mid-1;
j=mid;
}
}
if(j==data.size())return 0;
return data[j].second;
}
void erase(vector<ii>& data,int x){
int l=0,r=data.size()-1;
int j=data.size();
while(l<=r){
int mid=(l+r)/2;
if(data[mid].first<x)l=mid+1;
else{
r=mid-1;
j=mid;
}
}
assert(j!=data.size());
for(;j>=0;j--){
data[j].second--;
}
}
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
// freopen("q.in","r",stdin);
// freopen("q.out","w",stdout);
int n,q;
cin>>n>>q;
vector<int>Z;
vector<int>ans(q,0);
for(int i=0;i<n;i++){
int a,b;
cin>>a>>b;
arr.pb(Person(a,b,a+b,i));
Z.pb(i);
}
sort(all(arr));
for(int i=0;i<n;i++)arr[i].ind=i;
sort(all(Z),sort_by_Z);
sq=sqrt(n);
sz=n/sq+1;
for(int i=0;i<n;i++){
no.pb(i/sq);
}
data.resize(sz);
for(int i=0;i<n;i++){
data[no[i]].pb({arr[i].I,0});
}
for(int i=0;i<sz;i++){
int cnt=1;
sort(all(data[i]));
for(int j=data[i].size()-1;j>=0;j--){
data[i][j].second=cnt++;
}
}
vector<int>idq;
for(int i=0;i<q;i++){
int a,b,c;
cin>>a>>b>>c;
idq.pb(i);
Q.pb(Person(a,b,c,i));
}
sort(all(idq),Sort_by_Z);
int ptr=0;
vector<bool>vis(n,false);
for(int i=0;i<q;i++){
while(ptr!=n&&arr[Z[ptr]].Z<Q[idq[i]].Z){
vis[Z[ptr]]=true;
erase(data[no[arr[Z[ptr]].ind]],arr[Z[ptr]].I);
ptr++;
}
int l=0,r=n-1;
int j=n;
while(l<=r){
int mid=(l+r)/2;
if(arr[mid].M<Q[idq[i]].M)l=mid+1;
else{
r=mid-1;
j=mid;
}
}
if(j==n)continue;
while(j!=0&&j<n&&no[j]==no[j-1]){
if(vis[j]==false&&arr[j].I>=Q[idq[i]].I)
ans[idq[i]]++;
j++;
}
if(j==n)continue;
for(int N=no[j];N<sz;N++){
ans[idq[i]]+=query(data[N],Q[idq[i]].I);
}
}
for(int i=0;i<q;i++)cout<<ans[i]<<"\n";
}
Compilation message
examination.cpp: In function 'int query(std::vector<std::pair<int, int> >&, int)':
examination.cpp:47:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(j==data.size())return 0;
~^~~~~~~~~~~~~
In file included from /usr/include/c++/7/cassert:44:0,
from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:33,
from examination.cpp:1:
examination.cpp: In function 'void erase(std::vector<std::pair<int, int> >&, int)':
examination.cpp:61:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
assert(j!=data.size());
~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
504 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
1 ms |
376 KB |
Output is correct |
5 |
Correct |
3 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
10 ms |
892 KB |
Output is correct |
8 |
Correct |
10 ms |
804 KB |
Output is correct |
9 |
Correct |
10 ms |
812 KB |
Output is correct |
10 |
Correct |
8 ms |
692 KB |
Output is correct |
11 |
Correct |
8 ms |
760 KB |
Output is correct |
12 |
Correct |
6 ms |
632 KB |
Output is correct |
13 |
Correct |
8 ms |
760 KB |
Output is correct |
14 |
Correct |
7 ms |
760 KB |
Output is correct |
15 |
Correct |
9 ms |
760 KB |
Output is correct |
16 |
Correct |
6 ms |
760 KB |
Output is correct |
17 |
Correct |
8 ms |
676 KB |
Output is correct |
18 |
Correct |
5 ms |
632 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1300 ms |
12364 KB |
Output is correct |
2 |
Correct |
1273 ms |
12544 KB |
Output is correct |
3 |
Correct |
1275 ms |
12392 KB |
Output is correct |
4 |
Correct |
1204 ms |
11656 KB |
Output is correct |
5 |
Correct |
592 ms |
11620 KB |
Output is correct |
6 |
Correct |
563 ms |
10952 KB |
Output is correct |
7 |
Correct |
2085 ms |
12160 KB |
Output is correct |
8 |
Correct |
957 ms |
12268 KB |
Output is correct |
9 |
Correct |
1550 ms |
12172 KB |
Output is correct |
10 |
Correct |
513 ms |
11480 KB |
Output is correct |
11 |
Correct |
566 ms |
11456 KB |
Output is correct |
12 |
Correct |
270 ms |
10504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1300 ms |
12364 KB |
Output is correct |
2 |
Correct |
1273 ms |
12544 KB |
Output is correct |
3 |
Correct |
1275 ms |
12392 KB |
Output is correct |
4 |
Correct |
1204 ms |
11656 KB |
Output is correct |
5 |
Correct |
592 ms |
11620 KB |
Output is correct |
6 |
Correct |
563 ms |
10952 KB |
Output is correct |
7 |
Correct |
2085 ms |
12160 KB |
Output is correct |
8 |
Correct |
957 ms |
12268 KB |
Output is correct |
9 |
Correct |
1550 ms |
12172 KB |
Output is correct |
10 |
Correct |
513 ms |
11480 KB |
Output is correct |
11 |
Correct |
566 ms |
11456 KB |
Output is correct |
12 |
Correct |
270 ms |
10504 KB |
Output is correct |
13 |
Correct |
1324 ms |
12800 KB |
Output is correct |
14 |
Correct |
1358 ms |
12856 KB |
Output is correct |
15 |
Correct |
1303 ms |
12372 KB |
Output is correct |
16 |
Correct |
1205 ms |
12040 KB |
Output is correct |
17 |
Correct |
674 ms |
12060 KB |
Output is correct |
18 |
Correct |
565 ms |
10796 KB |
Output is correct |
19 |
Correct |
1350 ms |
12808 KB |
Output is correct |
20 |
Correct |
1331 ms |
12880 KB |
Output is correct |
21 |
Correct |
1735 ms |
12908 KB |
Output is correct |
22 |
Correct |
490 ms |
11528 KB |
Output is correct |
23 |
Correct |
583 ms |
11504 KB |
Output is correct |
24 |
Correct |
274 ms |
10456 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
504 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
1 ms |
376 KB |
Output is correct |
5 |
Correct |
3 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
10 ms |
892 KB |
Output is correct |
8 |
Correct |
10 ms |
804 KB |
Output is correct |
9 |
Correct |
10 ms |
812 KB |
Output is correct |
10 |
Correct |
8 ms |
692 KB |
Output is correct |
11 |
Correct |
8 ms |
760 KB |
Output is correct |
12 |
Correct |
6 ms |
632 KB |
Output is correct |
13 |
Correct |
8 ms |
760 KB |
Output is correct |
14 |
Correct |
7 ms |
760 KB |
Output is correct |
15 |
Correct |
9 ms |
760 KB |
Output is correct |
16 |
Correct |
6 ms |
760 KB |
Output is correct |
17 |
Correct |
8 ms |
676 KB |
Output is correct |
18 |
Correct |
5 ms |
632 KB |
Output is correct |
19 |
Correct |
1300 ms |
12364 KB |
Output is correct |
20 |
Correct |
1273 ms |
12544 KB |
Output is correct |
21 |
Correct |
1275 ms |
12392 KB |
Output is correct |
22 |
Correct |
1204 ms |
11656 KB |
Output is correct |
23 |
Correct |
592 ms |
11620 KB |
Output is correct |
24 |
Correct |
563 ms |
10952 KB |
Output is correct |
25 |
Correct |
2085 ms |
12160 KB |
Output is correct |
26 |
Correct |
957 ms |
12268 KB |
Output is correct |
27 |
Correct |
1550 ms |
12172 KB |
Output is correct |
28 |
Correct |
513 ms |
11480 KB |
Output is correct |
29 |
Correct |
566 ms |
11456 KB |
Output is correct |
30 |
Correct |
270 ms |
10504 KB |
Output is correct |
31 |
Correct |
1324 ms |
12800 KB |
Output is correct |
32 |
Correct |
1358 ms |
12856 KB |
Output is correct |
33 |
Correct |
1303 ms |
12372 KB |
Output is correct |
34 |
Correct |
1205 ms |
12040 KB |
Output is correct |
35 |
Correct |
674 ms |
12060 KB |
Output is correct |
36 |
Correct |
565 ms |
10796 KB |
Output is correct |
37 |
Correct |
1350 ms |
12808 KB |
Output is correct |
38 |
Correct |
1331 ms |
12880 KB |
Output is correct |
39 |
Correct |
1735 ms |
12908 KB |
Output is correct |
40 |
Correct |
490 ms |
11528 KB |
Output is correct |
41 |
Correct |
583 ms |
11504 KB |
Output is correct |
42 |
Correct |
274 ms |
10456 KB |
Output is correct |
43 |
Correct |
1401 ms |
14724 KB |
Output is correct |
44 |
Correct |
1370 ms |
14748 KB |
Output is correct |
45 |
Correct |
1347 ms |
14700 KB |
Output is correct |
46 |
Correct |
1197 ms |
13292 KB |
Output is correct |
47 |
Correct |
663 ms |
13204 KB |
Output is correct |
48 |
Correct |
568 ms |
10760 KB |
Output is correct |
49 |
Correct |
2223 ms |
14600 KB |
Output is correct |
50 |
Correct |
1161 ms |
14672 KB |
Output is correct |
51 |
Correct |
1762 ms |
14708 KB |
Output is correct |
52 |
Correct |
566 ms |
13064 KB |
Output is correct |
53 |
Correct |
562 ms |
12264 KB |
Output is correct |