Submission #248934

# Submission time Handle Problem Language Result Execution time Memory
248934 2020-07-13T18:25:41 Z kostia244 Ancient Books (IOI17_books) C++17
50 / 100
412 ms 58488 KB
#include "books.h"
#pragma GCC optimize("O2,unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2,ssse3")
#include<bits/extc++.h>
using namespace std;
const int maxn = 1<<20;
using ll = long long;
struct oset {
	vector<int> f;
	oset() : f(maxn) {}
	int insert(int x) {
		x++;
		for(; x < maxn; x += x&-x) f[x]++;
	}
	void erase(int x) {
		x++;
		for(; x < maxn; x += x&-x) f[x]--;
	}
	int order_of_key(int x) {
		int r = 0;
		for(; x > 0; x -= x&-x) r += f[x];
		return r;
	}
};
ll vis[maxn][4];
ll minimum_walk(vector<int> p, int s) {
	oset pref, suf;
	vector<int> pos(p.size());
	ll ans = 0, lst = -1, fi = -1;
	for(int i = 0; i < p.size(); i++) suf.insert(i), pos[p[i]] = i;
	for(int t, i = 0; i < p.size(); i++) {
		//cout << i << "::\n";
		
		int v = p[i];
		suf.erase(v);
		
		if(i != v) {
			vis[i][(v > i)*3]++;
			vis[i][1 + (pos[i]>i)]++;
		}
		
		t = i-pref.order_of_key(i+1);
		vis[i][1] += t, vis[i][3] += t;
		
		t = suf.order_of_key(i);
		vis[i][0] += t, vis[i][2] += t;
		
		pref.insert(v);
		
		if(vis[i][0] + vis[i][2] + vis[i][3] + vis[i][1]) {
			lst = i;
			if(fi == -1) fi = i;
		}
		//for(int j = 0; j < 4; j++) cout << vis[i][j] << " "; cout << endl;	
		
		if(i) {
			assert(vis[i][0] == vis[i-1][2]);
			assert(vis[i][1] == vis[i-1][3]);
		}
	}
	fi = min(fi, (ll)s);
	for(int i = fi; i <= lst; i++) {
		for(int j = 0; j < 4; j++) {
			if(i == lst && j >= 2) break;
			if(i == fi && j < 2) continue;
			if(vis[i][j] == 0) {
				vis[i][j]++;
				vis[i + (j<2?-1:1)][j^3]++;
			}
		}
	}
	for(int i = 0; i < p.size(); i++) {
		//cout << vis[i][0] << " " << vis[i][1] << " " << vis[i][2] << " " << vis[i][3] << " " << g[i] << endl;
		vis[i][2] = vis[i][3] = max(vis[i][2], vis[i][3]);
		vis[i][0] = vis[i][1] = max(vis[i][0], vis[i][1]);
		ans += (vis[i][0] + vis[i][2]);
	}
	return ans;
}

Compilation message

books.cpp: In member function 'int oset::insert(int)':
books.cpp:14:2: warning: no return statement in function returning non-void [-Wreturn-type]
  }
  ^
books.cpp: In function 'll minimum_walk(std::vector<int>, int)':
books.cpp:30:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < p.size(); i++) suf.insert(i), pos[p[i]] = i;
                 ~~^~~~~~~~~~
books.cpp:31:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int t, i = 0; i < p.size(); i++) {
                    ~~^~~~~~~~~~
books.cpp:72:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < p.size(); i++) {
                 ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 8576 KB Output is correct
2 Correct 4 ms 8576 KB Output is correct
3 Correct 5 ms 8576 KB Output is correct
4 Correct 5 ms 8576 KB Output is correct
5 Correct 5 ms 8576 KB Output is correct
6 Correct 5 ms 8576 KB Output is correct
7 Correct 5 ms 8576 KB Output is correct
8 Correct 5 ms 8576 KB Output is correct
9 Correct 5 ms 8576 KB Output is correct
10 Correct 4 ms 8576 KB Output is correct
11 Correct 5 ms 8576 KB Output is correct
12 Correct 5 ms 8576 KB Output is correct
13 Correct 5 ms 8576 KB Output is correct
14 Correct 5 ms 8576 KB Output is correct
15 Correct 5 ms 8576 KB Output is correct
16 Correct 4 ms 8576 KB Output is correct
17 Correct 5 ms 8576 KB Output is correct
18 Correct 5 ms 8576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 8576 KB Output is correct
2 Correct 4 ms 8576 KB Output is correct
3 Correct 5 ms 8576 KB Output is correct
4 Correct 5 ms 8576 KB Output is correct
5 Correct 5 ms 8576 KB Output is correct
6 Correct 5 ms 8576 KB Output is correct
7 Correct 5 ms 8576 KB Output is correct
8 Correct 5 ms 8576 KB Output is correct
9 Correct 5 ms 8576 KB Output is correct
10 Correct 4 ms 8576 KB Output is correct
11 Correct 5 ms 8576 KB Output is correct
12 Correct 5 ms 8576 KB Output is correct
13 Correct 5 ms 8576 KB Output is correct
14 Correct 5 ms 8576 KB Output is correct
15 Correct 5 ms 8576 KB Output is correct
16 Correct 4 ms 8576 KB Output is correct
17 Correct 5 ms 8576 KB Output is correct
18 Correct 5 ms 8576 KB Output is correct
19 Correct 5 ms 8576 KB Output is correct
20 Correct 5 ms 8576 KB Output is correct
21 Correct 5 ms 8576 KB Output is correct
22 Correct 5 ms 8576 KB Output is correct
23 Correct 5 ms 8576 KB Output is correct
24 Correct 5 ms 8576 KB Output is correct
25 Correct 5 ms 8576 KB Output is correct
26 Correct 5 ms 8576 KB Output is correct
27 Correct 5 ms 8576 KB Output is correct
28 Correct 6 ms 8576 KB Output is correct
29 Correct 5 ms 8576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 8576 KB Output is correct
2 Correct 4 ms 8576 KB Output is correct
3 Correct 5 ms 8576 KB Output is correct
4 Correct 5 ms 8576 KB Output is correct
5 Correct 5 ms 8576 KB Output is correct
6 Correct 5 ms 8576 KB Output is correct
7 Correct 5 ms 8576 KB Output is correct
8 Correct 5 ms 8576 KB Output is correct
9 Correct 5 ms 8576 KB Output is correct
10 Correct 4 ms 8576 KB Output is correct
11 Correct 5 ms 8576 KB Output is correct
12 Correct 5 ms 8576 KB Output is correct
13 Correct 5 ms 8576 KB Output is correct
14 Correct 5 ms 8576 KB Output is correct
15 Correct 5 ms 8576 KB Output is correct
16 Correct 4 ms 8576 KB Output is correct
17 Correct 5 ms 8576 KB Output is correct
18 Correct 5 ms 8576 KB Output is correct
19 Correct 5 ms 8576 KB Output is correct
20 Correct 5 ms 8576 KB Output is correct
21 Correct 5 ms 8576 KB Output is correct
22 Correct 5 ms 8576 KB Output is correct
23 Correct 5 ms 8576 KB Output is correct
24 Correct 5 ms 8576 KB Output is correct
25 Correct 5 ms 8576 KB Output is correct
26 Correct 5 ms 8576 KB Output is correct
27 Correct 5 ms 8576 KB Output is correct
28 Correct 6 ms 8576 KB Output is correct
29 Correct 5 ms 8576 KB Output is correct
30 Correct 391 ms 51580 KB Output is correct
31 Correct 412 ms 58376 KB Output is correct
32 Correct 272 ms 58308 KB Output is correct
33 Correct 284 ms 58360 KB Output is correct
34 Correct 277 ms 58360 KB Output is correct
35 Correct 276 ms 58360 KB Output is correct
36 Correct 278 ms 58360 KB Output is correct
37 Correct 282 ms 58360 KB Output is correct
38 Correct 287 ms 58488 KB Output is correct
39 Correct 288 ms 58360 KB Output is correct
40 Correct 295 ms 58360 KB Output is correct
41 Correct 317 ms 58360 KB Output is correct
42 Correct 309 ms 58360 KB Output is correct
43 Correct 279 ms 58364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 8576 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2744'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 8576 KB Output is correct
2 Correct 4 ms 8576 KB Output is correct
3 Correct 5 ms 8576 KB Output is correct
4 Correct 5 ms 8576 KB Output is correct
5 Correct 5 ms 8576 KB Output is correct
6 Correct 5 ms 8576 KB Output is correct
7 Correct 5 ms 8576 KB Output is correct
8 Correct 5 ms 8576 KB Output is correct
9 Correct 5 ms 8576 KB Output is correct
10 Correct 4 ms 8576 KB Output is correct
11 Correct 5 ms 8576 KB Output is correct
12 Correct 5 ms 8576 KB Output is correct
13 Correct 5 ms 8576 KB Output is correct
14 Correct 5 ms 8576 KB Output is correct
15 Correct 5 ms 8576 KB Output is correct
16 Correct 4 ms 8576 KB Output is correct
17 Correct 5 ms 8576 KB Output is correct
18 Correct 5 ms 8576 KB Output is correct
19 Correct 5 ms 8576 KB Output is correct
20 Correct 5 ms 8576 KB Output is correct
21 Correct 5 ms 8576 KB Output is correct
22 Correct 5 ms 8576 KB Output is correct
23 Correct 5 ms 8576 KB Output is correct
24 Correct 5 ms 8576 KB Output is correct
25 Correct 5 ms 8576 KB Output is correct
26 Correct 5 ms 8576 KB Output is correct
27 Correct 5 ms 8576 KB Output is correct
28 Correct 6 ms 8576 KB Output is correct
29 Correct 5 ms 8576 KB Output is correct
30 Correct 391 ms 51580 KB Output is correct
31 Correct 412 ms 58376 KB Output is correct
32 Correct 272 ms 58308 KB Output is correct
33 Correct 284 ms 58360 KB Output is correct
34 Correct 277 ms 58360 KB Output is correct
35 Correct 276 ms 58360 KB Output is correct
36 Correct 278 ms 58360 KB Output is correct
37 Correct 282 ms 58360 KB Output is correct
38 Correct 287 ms 58488 KB Output is correct
39 Correct 288 ms 58360 KB Output is correct
40 Correct 295 ms 58360 KB Output is correct
41 Correct 317 ms 58360 KB Output is correct
42 Correct 309 ms 58360 KB Output is correct
43 Correct 279 ms 58364 KB Output is correct
44 Incorrect 5 ms 8576 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2744'
45 Halted 0 ms 0 KB -