답안 #804026

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
804026 2023-08-03T06:54:28 Z 박영우(#10104) Vera and Modern Art (CCO17_art) C++17
15 / 25
1634 ms 224772 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
#define MAX 6010101
#define MAXS 20
#define INF 1000000000000000001
#define bb ' '
#define ln '\n'
#define Ln '\n'
#define MOD 1000000007
ll sum[MAX];
int ch[2][MAX];
int cnt = 0;
void upd(int n, ll x, ll v) {
	if (!x) {
		sum[n] += v;
		return;
	}
	int c = x & 1;
	if (!ch[c][n]) ch[c][n] = ++cnt;
	upd(ch[c][n], x >> 1ll, v);
}
ll get(int n, ll x) {
	if (!n) return 0;
	if (!x) return 0;
	int c = x & 1;
	return sum[ch[1][n]] + get(ch[c][n], x >> 1ll);
}
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;
	vector<ll> xst;
	vector<int> sind;
	ll pv = -1;
	for (auto& [a, b] : mp) {
		if (pv != a.first) {
			pv = a.first;
			cnt++;
			sind.push_back(cnt);
			xst.push_back(a.first);
		}
		upd(sind.back(), a.second, b);
		v.emplace_back(a, b);
	}
	while (Q--) {
		cin >> a >> b;
		int i;
		ll sum = 0;
		for (i = 0; i <= 62; i++) {
			if (a < (1ll << i)) break;
			ll x, mi;
			mi = (1ll << i) - 1;
			x = a & mi;
			x += mi + 1;
			int ind = lower_bound(xst.begin(), xst.end(), x) - xst.begin();
			if (ind == xst.size() || xst[ind] != x) continue;
			sum += get(sind[ind], b);
		}
		cout << sum << Ln;
	}
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:67:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |    if (ind == xst.size() || xst[ind] != x) continue;
      |        ~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 5 ms 2400 KB Output is correct
3 Correct 6 ms 2504 KB Output is correct
4 Correct 12 ms 1492 KB Output is correct
5 Correct 11 ms 1540 KB Output is correct
6 Correct 7 ms 1492 KB Output is correct
7 Correct 6 ms 1492 KB Output is correct
8 Correct 6 ms 1492 KB Output is correct
9 Correct 7 ms 1536 KB Output is correct
10 Correct 5 ms 1492 KB Output is correct
11 Correct 5 ms 1492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 622 ms 26568 KB Output is correct
2 Correct 608 ms 26536 KB Output is correct
3 Correct 1634 ms 22536 KB Output is correct
4 Correct 1587 ms 22632 KB Output is correct
5 Correct 846 ms 22548 KB Output is correct
6 Correct 793 ms 22620 KB Output is correct
7 Correct 823 ms 22568 KB Output is correct
8 Correct 835 ms 22536 KB Output is correct
9 Correct 842 ms 22672 KB Output is correct
10 Correct 818 ms 22664 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 238 ms 59052 KB Output is correct
3 Correct 239 ms 59856 KB Output is correct
4 Correct 586 ms 32860 KB Output is correct
5 Correct 585 ms 32952 KB Output is correct
6 Correct 301 ms 33144 KB Output is correct
7 Correct 304 ms 33044 KB Output is correct
8 Correct 289 ms 33228 KB Output is correct
9 Correct 327 ms 33012 KB Output is correct
10 Correct 284 ms 33192 KB Output is correct
11 Correct 277 ms 33048 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 5 ms 2400 KB Output is correct
3 Correct 6 ms 2504 KB Output is correct
4 Correct 12 ms 1492 KB Output is correct
5 Correct 11 ms 1540 KB Output is correct
6 Correct 7 ms 1492 KB Output is correct
7 Correct 6 ms 1492 KB Output is correct
8 Correct 6 ms 1492 KB Output is correct
9 Correct 7 ms 1536 KB Output is correct
10 Correct 5 ms 1492 KB Output is correct
11 Correct 5 ms 1492 KB Output is correct
12 Correct 622 ms 26568 KB Output is correct
13 Correct 608 ms 26536 KB Output is correct
14 Correct 1634 ms 22536 KB Output is correct
15 Correct 1587 ms 22632 KB Output is correct
16 Correct 846 ms 22548 KB Output is correct
17 Correct 793 ms 22620 KB Output is correct
18 Correct 823 ms 22568 KB Output is correct
19 Correct 835 ms 22536 KB Output is correct
20 Correct 842 ms 22672 KB Output is correct
21 Correct 818 ms 22664 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 238 ms 59052 KB Output is correct
24 Correct 239 ms 59856 KB Output is correct
25 Correct 586 ms 32860 KB Output is correct
26 Correct 585 ms 32952 KB Output is correct
27 Correct 301 ms 33144 KB Output is correct
28 Correct 304 ms 33044 KB Output is correct
29 Correct 289 ms 33228 KB Output is correct
30 Correct 327 ms 33012 KB Output is correct
31 Correct 284 ms 33192 KB Output is correct
32 Correct 277 ms 33048 KB Output is correct
33 Runtime error 281 ms 224772 KB Execution killed with signal 11
34 Halted 0 ms 0 KB -