#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
#define MAX 110
#define MAXS 20
#define INF 1000000000000000001
#define bb ' '
#define ln '\n'
#define Ln '\n'
#define MOD 1000000007
signed main() {
ios::sync_with_stdio(false), cin.tie(0);
int N, Q;
cin >> N >> Q;
int i;
ll a, b, c;
map<pll, ll> mp;
for (i = 1; i <= N; i++) {
cin >> a >> b >> c;
mp[pll(a, b)] += c;
}
vector<pair<pll, ll>> v;
for (auto& [a, b] : mp) v.emplace_back(a, b);
while (Q--) {
cin >> a >> b;
int i, j;
ll sum = 0;
for (i = 0; i <= 62; i++) {
if (a < (1ll << i)) continue;
for (j = 0; j <= 62; j++) {
if (b < (1ll << j)) continue;
ll mi, mj;
mi = 1ll << i;
mj = 1ll << j;
mi--;
mj--;
ll x, y;
x = a & mi;
y = b & mj;
x += mi + 1;
y += mj + 1;
int ind = lower_bound(v.begin(), v.end(), pair<pll, ll>(pll(x, y), 0)) - v.begin();
if (ind < v.size() && v[ind].first == pll(x, y)) sum += v[ind].second;
}
}
cout << sum << Ln;
}
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:45:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<long long int, long long int>, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
45 | if (ind < v.size() && v[ind].first == pll(x, y)) sum += v[ind].second;
| ~~~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
139 ms |
528 KB |
Output is correct |
3 |
Correct |
146 ms |
524 KB |
Output is correct |
4 |
Correct |
143 ms |
544 KB |
Output is correct |
5 |
Correct |
143 ms |
524 KB |
Output is correct |
6 |
Correct |
48 ms |
524 KB |
Output is correct |
7 |
Correct |
46 ms |
468 KB |
Output is correct |
8 |
Correct |
46 ms |
540 KB |
Output is correct |
9 |
Correct |
46 ms |
540 KB |
Output is correct |
10 |
Correct |
45 ms |
528 KB |
Output is correct |
11 |
Correct |
46 ms |
544 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
4069 ms |
19036 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
2609 ms |
9792 KB |
Output is correct |
3 |
Correct |
2470 ms |
9800 KB |
Output is correct |
4 |
Execution timed out |
4059 ms |
9572 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
139 ms |
528 KB |
Output is correct |
3 |
Correct |
146 ms |
524 KB |
Output is correct |
4 |
Correct |
143 ms |
544 KB |
Output is correct |
5 |
Correct |
143 ms |
524 KB |
Output is correct |
6 |
Correct |
48 ms |
524 KB |
Output is correct |
7 |
Correct |
46 ms |
468 KB |
Output is correct |
8 |
Correct |
46 ms |
540 KB |
Output is correct |
9 |
Correct |
46 ms |
540 KB |
Output is correct |
10 |
Correct |
45 ms |
528 KB |
Output is correct |
11 |
Correct |
46 ms |
544 KB |
Output is correct |
12 |
Execution timed out |
4069 ms |
19036 KB |
Time limit exceeded |
13 |
Halted |
0 ms |
0 KB |
- |