/*raghav0307 - Raghav Gupta*/
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
#define fast_io() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef long long ll;
typedef pair<int, int> pii;
typedef long double ld;
#define int ll
const int MAXN = 1e5 + 5;
bool custom(pair<int, int> a, pair<int, int> b){
if(a.ff + a.ss > b.ff + b.ss)
return false;
return true;
}
int bit[MAXN], ans[MAXN], rule[MAXN][3];
pair<int, int> score[MAXN];
void add(int pos, int delta){
for( ; pos < MAXN; pos = pos | ( pos + 1))
bit[pos] += delta;
}
int sum(int pos){
int ans = 0;
for( ; pos >= 0; pos = (pos & (pos+1)) - 1)
ans += bit[pos];
return ans;
}
int sum(int l, int r){
return sum(r) - sum(l-1);
}
signed main(){
fast_io();
int n, q;
cin >> n >> q;
for(int i = 0; i < n; i++){
cin >> score[i].ff >> score[i].ss;
}
sort(score, score + n);
vector<pair<pii, int> > criter;
for(int i = 0; i < q; i++){
cin >> rule[i][0] >> rule[i][1] >> rule[i][2];
}
for(int i = 0; i < q; i++){
if(rule[i][0] + rule[i][1] >= rule[i][2]){
criter.pb({{rule[i][0], rule[i][1]}, i});
}
}
sort(criter.begin(), criter.end());
int at = n-1;
while(!criter.empty()){
auto x = criter.back(); criter.pop_back();
while(at >= 0 and score[at].ff >= x.ff.ff){
add(score[at].ss, 1);
at--;
}
ans[x.ss] = sum(x.ff.ss, MAXN-1);
}
vector<pii> criter2;
for(int i = 0; i < q; i++){
if(rule[i][0] + rule[i][1] < rule[i][2]){
criter2.pb({rule[i][2], i});
}
}
sort(criter2.begin(), criter2.end());
sort(score, score + n, custom);
// for(int i = 0; i < n; i++)
// cout << score[i].ff << " " << score[i].ss << "\n";
// for(auto x : criter2)
// cout << x.ff << " " << x.ss << "\n";
memset(bit, 0, sizeof(bit));
at = n-1;
for(int i = criter2.size() - 1; i >= 0; i--){
while(at >= 0 and score[at].ff + score[at].ss >= criter2[i].ff){
add(score[at].ff, 1);
at--;
}
ans[criter2[i].ss] += n - at - 1;
ans[criter2[i].ss] -= sum(0, rule[criter2[i].ss][0] - 1);
}
memset(bit, 0, sizeof(bit));
at = n-1;
for(int i = criter2.size() - 1; i >= 0; i--){
while(at >= 0 and score[at].ff + score[at].ss >= criter2[i].ff){
add(score[at].ss, 1);
at--;
}
ans[criter2[i].ss] -= sum(0, rule[criter2[i].ss][1] - 1);
}
for(int i = 0; i < q; i++)
cout << ans[i] << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1152 KB |
Output is correct |
2 |
Correct |
3 ms |
1152 KB |
Output is correct |
3 |
Correct |
2 ms |
1200 KB |
Output is correct |
4 |
Runtime error |
2 ms |
512 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
87 ms |
8080 KB |
Output is correct |
2 |
Correct |
84 ms |
8140 KB |
Output is correct |
3 |
Correct |
84 ms |
8040 KB |
Output is correct |
4 |
Correct |
73 ms |
8140 KB |
Output is correct |
5 |
Correct |
78 ms |
8076 KB |
Output is correct |
6 |
Runtime error |
2017 ms |
12380 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
87 ms |
8080 KB |
Output is correct |
2 |
Correct |
84 ms |
8140 KB |
Output is correct |
3 |
Correct |
84 ms |
8040 KB |
Output is correct |
4 |
Correct |
73 ms |
8140 KB |
Output is correct |
5 |
Correct |
78 ms |
8076 KB |
Output is correct |
6 |
Runtime error |
2017 ms |
12380 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1152 KB |
Output is correct |
2 |
Correct |
3 ms |
1152 KB |
Output is correct |
3 |
Correct |
2 ms |
1200 KB |
Output is correct |
4 |
Runtime error |
2 ms |
512 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
5 |
Halted |
0 ms |
0 KB |
- |