#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
using namespace std;
struct Data{
long long x, y;
int sum;
Data(long long x, long long y, int sum):x(x), y(y), sum(sum){}
bool operator<(const Data&r)const{
return x < r.x || (x == r.x && y < r.y);
}
};
vector<Data> srt[70][70];
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
auto len = [&](int x){
return 64 - __builtin_clzll(x);
};
int n, q;
cin >> n >> q;
for(int i = 0; i < n; ++i){
long long x, y;
int v;
cin >> x >> y >> v;
srt[len(x) - 1][len(y) - 1].push_back({x, y, v});
}
for(int i = 0; i < 70; ++i){
for(int j = 0; j < 70; ++j){
sort(srt[i][j].begin(), srt[i][j].end());
for(int k = 1; k < (int)srt[i][j].size(); ++k){
srt[i][j][k].sum += srt[i][j][k - 1].sum;
}
}
}
for(int rep = 0; rep < q; ++rep){
long long x, y;
cin >> x >> y;
int ans = 0;
for(int i = 0; (1ll << i) <= x; ++i){
for(int j = 0; (1ll << j) <= y; ++j){
if(!(int)srt[i][j].size()) continue;
long long px = x % (1ll << i) + (1ll << i);
long long py = y % (1ll << j) + (1ll << j);
int p1 = lower_bound(srt[i][j].begin(), srt[i][j].end(), Data(px, py, -1)) - srt[i][j].begin();
int p2 = lower_bound(srt[i][j].begin(), srt[i][j].end(), Data(px, py + 1, -1)) - srt[i][j].begin() - 1;
if(p1 <= p2){
ans += srt[i][j][p2].sum;
if(p1) ans -= srt[i][j][p1 - 1].sum;
}
}
}
cout << ans << '\n';
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Incorrect |
16 ms |
508 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1760 ms |
6348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
293 ms |
3668 KB |
Output is correct |
3 |
Correct |
313 ms |
3724 KB |
Output is correct |
4 |
Execution timed out |
4078 ms |
3928 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Incorrect |
16 ms |
508 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |