#include<bits/stdc++.h>
#define fo(i,d,c) for(int i=d;i<=c;i++)
#define fod(i,c,d) for(int i=c;i>=d;i--)
#define maxn 1000010
#define N 1010
#define fi first
#define se second
#define pb emplace_back
#define en cout<<"\n";
//#define int long long
#define inf 1000000000
#define pii pair<int,int>
#define vii vector<pii>
#define lb(x) x&-x
#define bit(i,j) ((i>>j)&1)
#define offbit(i,j) (i^(1<<j))
#define onbit(i,j) (i|(1<<j))
#define vi vector<int>
template <typename T1, typename T2> bool minimize(T1 &a, T2 b)
{
if (a > b)
{
a = b;
return true;
}
return false;
}
template <typename T1, typename T2> bool maximize(T1 &a, T2 b)
{
if (a < b)
{
a = b;
return true;
}
return false;
}
using namespace std;
struct BIT
{
int t[maxn];
void up(int x,int val)
{
x++;
for( ; x < maxn ; x += lb(x)) t[x] += val;
}
int get(int x)
{
int ans = 0;
for( ; x ; x -= lb(x)) ans += t[x];
return ans;
}
} t1;
const int BLOCK = 500;
struct query
{
int A, B, C, id;
bool operator < (query y)
{
return make_pair(A / BLOCK, B) < make_pair(y.A / BLOCK, y.B);
}
};
vector<query> v;
int n,q;
vii v1,v2;
vi v3;
int nen[maxn],s[maxn],t[maxn],cnt[maxn],ans[maxn];
main()
{
#define name "TASK"
if(fopen(name".inp","r"))
{
freopen(name".inp","r",stdin);
freopen(name".out","w",stdout);
}
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> q;
fo(i,1,n)
{
cin >> s[i] >> t[i];
v1.push_back({s[i], i});
v2.push_back({t[i], i});
v3.push_back(s[i] + t[i]);
}
sort(v1.begin(),v1.end());
sort(v2.begin(),v2.end());
sort(v3.begin(),v3.end());
// for(int it : v3) cout << it << ' ';
// en;
fo(i,1,n) nen[i] = lower_bound(v3.begin(),v3.end(),s[i] + t[i]) - v3.begin();
fo(i,1,q)
{
int A,B,C;
cin >> A >> B >> C;
// cout << A << ' ' << B << ' ' << C << "\n";
int x = lower_bound(v1.begin(),v1.end(),make_pair(A, 0)) - v1.begin();
int y = lower_bound(v2.begin(),v2.end(),make_pair(B,0)) - v2.begin();
int z = lower_bound(v3.begin(),v3.end(),C) - v3.begin();
// cout << x << ' ' << y << ' ' << z << "\n";
v.push_back({x,y,z,i});
}
sort(v.begin(),v.end());
int l = n,r = n;
// fo(i,0,n - 1) cout << cnt[i] << ' ' ;
// en;
for(auto [A,B,C,id] : v)
{
// cout << A << ' ' << B << ' ' << C << ' ' << id << ' ' << l << ' ' << r << "\n";
while(A < l)
{
cnt[v1[l - 1].se]++;
// cout << v1[l - 1].se << "\n";
if(cnt[v1[l - 1].se] == 2) t1.up(nen[v1[l - 1].se],1);
l--;
}
while(A > l)
{
// cout << "ccc";
// en;
cnt[v1[l].se]--;
if(cnt[v1[l].se] == 1) t1.up(nen[v1[l].se],-1);
l++;
}
while(B < r)
{
cnt[v2[r - 1].se]++;
if(cnt[v2[r - 1].se] == 2) t1.up(nen[v2[r - 1].se],1);
r--;
}
while(B > r)
{
cnt[v2[r].se]--;
if(cnt[v2[r].se] == 1) t1.up(nen[v2[r].se],-1);
r++;
}
// cout << l << ' ' << r << "\n";
// fo(i,1,n) cout << cnt[i] << ' ';
// en;
ans[id] = t1.get(maxn - 3) - t1.get(C);
}
fo(i,1,q) cout << ans[i] << "\n";
}
Compilation message
examination.cpp:67:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
67 | main()
| ^~~~
examination.cpp: In function 'int main()':
examination.cpp:72:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
72 | freopen(name".inp","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
examination.cpp:73:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
73 | freopen(name".out","w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
12636 KB |
Output is correct |
2 |
Correct |
2 ms |
12636 KB |
Output is correct |
3 |
Correct |
2 ms |
12636 KB |
Output is correct |
4 |
Correct |
2 ms |
12636 KB |
Output is correct |
5 |
Correct |
2 ms |
12632 KB |
Output is correct |
6 |
Correct |
2 ms |
12636 KB |
Output is correct |
7 |
Correct |
12 ms |
13148 KB |
Output is correct |
8 |
Correct |
14 ms |
13144 KB |
Output is correct |
9 |
Correct |
15 ms |
13148 KB |
Output is correct |
10 |
Correct |
13 ms |
12940 KB |
Output is correct |
11 |
Correct |
12 ms |
13092 KB |
Output is correct |
12 |
Correct |
10 ms |
13032 KB |
Output is correct |
13 |
Correct |
12 ms |
12892 KB |
Output is correct |
14 |
Correct |
12 ms |
12892 KB |
Output is correct |
15 |
Correct |
12 ms |
12912 KB |
Output is correct |
16 |
Correct |
4 ms |
12892 KB |
Output is correct |
17 |
Correct |
12 ms |
12932 KB |
Output is correct |
18 |
Correct |
4 ms |
12892 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1052 ms |
24612 KB |
Output is correct |
2 |
Correct |
1048 ms |
24860 KB |
Output is correct |
3 |
Correct |
1039 ms |
24456 KB |
Output is correct |
4 |
Correct |
827 ms |
23872 KB |
Output is correct |
5 |
Correct |
133 ms |
23928 KB |
Output is correct |
6 |
Correct |
98 ms |
23032 KB |
Output is correct |
7 |
Correct |
395 ms |
24492 KB |
Output is correct |
8 |
Correct |
497 ms |
24520 KB |
Output is correct |
9 |
Correct |
434 ms |
24316 KB |
Output is correct |
10 |
Correct |
103 ms |
23596 KB |
Output is correct |
11 |
Correct |
828 ms |
23620 KB |
Output is correct |
12 |
Correct |
54 ms |
22776 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1052 ms |
24612 KB |
Output is correct |
2 |
Correct |
1048 ms |
24860 KB |
Output is correct |
3 |
Correct |
1039 ms |
24456 KB |
Output is correct |
4 |
Correct |
827 ms |
23872 KB |
Output is correct |
5 |
Correct |
133 ms |
23928 KB |
Output is correct |
6 |
Correct |
98 ms |
23032 KB |
Output is correct |
7 |
Correct |
395 ms |
24492 KB |
Output is correct |
8 |
Correct |
497 ms |
24520 KB |
Output is correct |
9 |
Correct |
434 ms |
24316 KB |
Output is correct |
10 |
Correct |
103 ms |
23596 KB |
Output is correct |
11 |
Correct |
828 ms |
23620 KB |
Output is correct |
12 |
Correct |
54 ms |
22776 KB |
Output is correct |
13 |
Correct |
1071 ms |
25048 KB |
Output is correct |
14 |
Correct |
1069 ms |
24876 KB |
Output is correct |
15 |
Correct |
1026 ms |
24612 KB |
Output is correct |
16 |
Correct |
844 ms |
24060 KB |
Output is correct |
17 |
Correct |
156 ms |
24060 KB |
Output is correct |
18 |
Correct |
103 ms |
23040 KB |
Output is correct |
19 |
Correct |
1107 ms |
25048 KB |
Output is correct |
20 |
Correct |
1079 ms |
25024 KB |
Output is correct |
21 |
Correct |
656 ms |
24976 KB |
Output is correct |
22 |
Correct |
91 ms |
23544 KB |
Output is correct |
23 |
Correct |
841 ms |
23600 KB |
Output is correct |
24 |
Correct |
54 ms |
22672 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
12636 KB |
Output is correct |
2 |
Correct |
2 ms |
12636 KB |
Output is correct |
3 |
Correct |
2 ms |
12636 KB |
Output is correct |
4 |
Correct |
2 ms |
12636 KB |
Output is correct |
5 |
Correct |
2 ms |
12632 KB |
Output is correct |
6 |
Correct |
2 ms |
12636 KB |
Output is correct |
7 |
Correct |
12 ms |
13148 KB |
Output is correct |
8 |
Correct |
14 ms |
13144 KB |
Output is correct |
9 |
Correct |
15 ms |
13148 KB |
Output is correct |
10 |
Correct |
13 ms |
12940 KB |
Output is correct |
11 |
Correct |
12 ms |
13092 KB |
Output is correct |
12 |
Correct |
10 ms |
13032 KB |
Output is correct |
13 |
Correct |
12 ms |
12892 KB |
Output is correct |
14 |
Correct |
12 ms |
12892 KB |
Output is correct |
15 |
Correct |
12 ms |
12912 KB |
Output is correct |
16 |
Correct |
4 ms |
12892 KB |
Output is correct |
17 |
Correct |
12 ms |
12932 KB |
Output is correct |
18 |
Correct |
4 ms |
12892 KB |
Output is correct |
19 |
Correct |
1052 ms |
24612 KB |
Output is correct |
20 |
Correct |
1048 ms |
24860 KB |
Output is correct |
21 |
Correct |
1039 ms |
24456 KB |
Output is correct |
22 |
Correct |
827 ms |
23872 KB |
Output is correct |
23 |
Correct |
133 ms |
23928 KB |
Output is correct |
24 |
Correct |
98 ms |
23032 KB |
Output is correct |
25 |
Correct |
395 ms |
24492 KB |
Output is correct |
26 |
Correct |
497 ms |
24520 KB |
Output is correct |
27 |
Correct |
434 ms |
24316 KB |
Output is correct |
28 |
Correct |
103 ms |
23596 KB |
Output is correct |
29 |
Correct |
828 ms |
23620 KB |
Output is correct |
30 |
Correct |
54 ms |
22776 KB |
Output is correct |
31 |
Correct |
1071 ms |
25048 KB |
Output is correct |
32 |
Correct |
1069 ms |
24876 KB |
Output is correct |
33 |
Correct |
1026 ms |
24612 KB |
Output is correct |
34 |
Correct |
844 ms |
24060 KB |
Output is correct |
35 |
Correct |
156 ms |
24060 KB |
Output is correct |
36 |
Correct |
103 ms |
23040 KB |
Output is correct |
37 |
Correct |
1107 ms |
25048 KB |
Output is correct |
38 |
Correct |
1079 ms |
25024 KB |
Output is correct |
39 |
Correct |
656 ms |
24976 KB |
Output is correct |
40 |
Correct |
91 ms |
23544 KB |
Output is correct |
41 |
Correct |
841 ms |
23600 KB |
Output is correct |
42 |
Correct |
54 ms |
22672 KB |
Output is correct |
43 |
Correct |
1061 ms |
27132 KB |
Output is correct |
44 |
Correct |
1106 ms |
27012 KB |
Output is correct |
45 |
Correct |
1065 ms |
26956 KB |
Output is correct |
46 |
Correct |
845 ms |
25432 KB |
Output is correct |
47 |
Correct |
157 ms |
25328 KB |
Output is correct |
48 |
Correct |
102 ms |
23020 KB |
Output is correct |
49 |
Correct |
403 ms |
26876 KB |
Output is correct |
50 |
Correct |
526 ms |
26884 KB |
Output is correct |
51 |
Correct |
471 ms |
26868 KB |
Output is correct |
52 |
Correct |
110 ms |
25092 KB |
Output is correct |
53 |
Correct |
811 ms |
24564 KB |
Output is correct |