Submission #36009

# Submission time Handle Problem Language Result Execution time Memory
36009 2017-12-04T08:13:43 Z minkank Fortune Telling 2 (JOI14_fortune_telling2) C++14
69 / 100
373 ms 78572 KB
#include <bits/stdc++.h>
using namespace std;

const int N = 2e5 + 5;

int n, m, a[N], b[N], c[N], last[21][3 * N], lg[3 * N], bit[3 * N];
vector<int> Value, Query[3 * N];
long long ans;

void upd(int pos) {
	for(pos; pos > 0; pos -= pos & -pos) bit[pos]++;
}

int get(int pos) {
	int res = 0;
	for(pos; pos < 3 * N; pos += pos & -pos) res += bit[pos];
	return res;
}

void getint(int &x) {
	x = 0;
	char c = getchar();
	while('0' > c || c > '9') c = getchar();
	while('0' <= c && c <= '9') x = (x << 3) + (x << 1) + c - '0', c = getchar();
}

int main() {
	getint(n); getint(m);
	for(int i = 0; i < 3 * N; ++i) lg[i] = log2(i);
	for(int i = 1; i <= n; ++i) getint(a[i]), getint(b[i]), Value.push_back(a[i]), Value.push_back(b[i]);
	for(int i = 1; i <= m; ++i) getint(c[i]), Value.push_back(c[i]);
	Value.push_back(0);
	sort(Value.begin(), Value.end());
	Value.resize(distance(Value.begin(), unique(Value.begin(), Value.end())));
	for(int i = 1; i <= n; ++i) 
		a[i] = lower_bound(Value.begin(), Value.end(), a[i]) - Value.begin() + 1,
		b[i] = lower_bound(Value.begin(), Value.end(), b[i]) - Value.begin() + 1;
	for(int i = 1; i <= m; ++i)
		c[i] = lower_bound(Value.begin(), Value.end(), c[i]) - Value.begin() + 1;
	for(int i = m; i >= 1; --i) if(!last[0][c[i]]) last[0][c[i]] = i;
	for(int i = 1; i <= 20; ++i) for(int j = 1; j < 3 * N; ++j)
		last[i][j] = max(last[i - 1][j], last[i - 1][j + (1 << (i - 1))]);
	for(int i = 1; i <= n; ++i) {
		if(a[i] == b[i]) {
			ans += a[i];
			continue;
		}
		int mn = min(a[i], b[i]), mx = max(a[i], b[i]) - 1;
		int pos = max(last[lg[mx - mn + 1]][mn], last[lg[mx - mn + 1]][mx - (1 << lg[mx - mn + 1]) + 1]);
		Query[pos].push_back(i);
	}
	for(int i = m; i >= 0; --i) {
		for(auto j: Query[i]) {
			if(i && a[j] < b[j]) swap(a[j], b[j]);
			if(get(a[j]) & 1) ans += Value[b[j] - 1];
			else ans += Value[a[j] - 1];
		}
		upd(c[i]);
	}
	printf("%lld", ans);
}

Compilation message

fortune_telling2.cpp: In function 'void upd(int)':
fortune_telling2.cpp:11:9: warning: statement has no effect [-Wunused-value]
  for(pos; pos > 0; pos -= pos & -pos) bit[pos]++;
         ^
fortune_telling2.cpp: In function 'int get(int)':
fortune_telling2.cpp:16:9: warning: statement has no effect [-Wunused-value]
  for(pos; pos < 3 * N; pos += pos & -pos) res += bit[pos];
         ^
# Verdict Execution time Memory Grader output
1 Correct 29 ms 72344 KB Output is correct
2 Correct 29 ms 72344 KB Output is correct
3 Correct 26 ms 72344 KB Output is correct
4 Correct 29 ms 72344 KB Output is correct
5 Correct 36 ms 72344 KB Output is correct
6 Correct 36 ms 72344 KB Output is correct
7 Correct 36 ms 72344 KB Output is correct
8 Correct 23 ms 72344 KB Output is correct
9 Correct 29 ms 72344 KB Output is correct
10 Correct 36 ms 72344 KB Output is correct
11 Correct 36 ms 72344 KB Output is correct
12 Correct 33 ms 72344 KB Output is correct
13 Correct 43 ms 72344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 46 ms 72616 KB Output is correct
2 Correct 66 ms 72852 KB Output is correct
3 Correct 79 ms 73196 KB Output is correct
4 Correct 79 ms 73196 KB Output is correct
5 Correct 79 ms 73248 KB Output is correct
6 Correct 83 ms 73196 KB Output is correct
7 Correct 86 ms 73204 KB Output is correct
8 Correct 73 ms 73448 KB Output is correct
9 Correct 66 ms 73196 KB Output is correct
10 Correct 53 ms 73196 KB Output is correct
11 Correct 73 ms 73224 KB Output is correct
12 Correct 63 ms 73448 KB Output is correct
13 Correct 69 ms 73196 KB Output is correct
14 Correct 76 ms 73196 KB Output is correct
15 Correct 73 ms 73236 KB Output is correct
16 Incorrect 73 ms 73300 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 133 ms 73964 KB Output is correct
2 Correct 179 ms 75500 KB Output is correct
3 Correct 229 ms 75500 KB Output is correct
4 Correct 323 ms 78572 KB Output is correct
5 Correct 116 ms 73964 KB Output is correct
6 Correct 353 ms 78572 KB Output is correct
7 Correct 356 ms 78572 KB Output is correct
8 Correct 329 ms 78572 KB Output is correct
9 Correct 343 ms 78572 KB Output is correct
10 Correct 333 ms 78572 KB Output is correct
11 Correct 296 ms 78572 KB Output is correct
12 Correct 333 ms 78572 KB Output is correct
13 Correct 373 ms 78572 KB Output is correct
14 Correct 243 ms 78572 KB Output is correct
15 Correct 223 ms 78572 KB Output is correct
16 Correct 263 ms 78572 KB Output is correct
17 Correct 223 ms 78572 KB Output is correct
18 Correct 226 ms 78572 KB Output is correct
19 Correct 269 ms 78572 KB Output is correct
20 Correct 279 ms 78572 KB Output is correct