Submission #58914

# Submission time Handle Problem Language Result Execution time Memory
58914 2018-07-19T19:49:44 Z egorlifar Bubble Sort 2 (JOI18_bubblesort2) C++17
60 / 100
2859 ms 46572 KB
/*
ЗАПУСКАЕМ 
░ГУСЯ░▄▀▀▀▄░РАБОТЯГУ░░
▄███▀░◐░░░▌░░░░░░░
░░░░▌░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▌░░░░░▐▄▄░░░░░
░░░░▌░░░░▄▀▒▒▀▀▀▀▄
░░░▐░░░░▐▒▒▒▒▒▒▒▒▀▀▄
░░░▐░░░░▐▄▒▒▒▒▒▒▒▒▒▒▀▄
░░░░▀▄░░░░▀▄▒▒▒▒▒▒▒▒▒▒▀▄
░░░░░░▀▄▄▄▄▄█▄▄▄▄▄▄▄▄▄▄▄▀▄
░░░░░░░░░░░▌▌░▌▌░░░░░
░░░░░░░░░░░▌▌░▌▌░░░░░
░░░░░░░░░▄▄▌▌▄▌▌░░░░░ 
 */
#pragma GCC target("sse4,tune=native")
#pragma GCC optimize("O3","unroll-loops")
#include "bubblesort2.h"
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <iomanip>
#include <deque>
    
     
using namespace std;
#define sz(c) (int)(c).size()
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define left left228
#define right right228
#define next next228
#define rank rank228
#define prev prev228
#define y1 y1228                                                         
#define read(FILENAME) freopen((FILENAME + ".in").c_str(), "r", stdin)
#define write(FILENAME) freopen((FILENAME + ".out").c_str(), "w", stdout)
#define files(FILENAME) read(FILENAME), write(FILENAME)
#define pb push_back
#define x first
#define y second
template<typename T1, typename T2>inline void chkmin(T1 &x, T2 y) { if (x > y) x = y; }
template<typename T1, typename T2>inline void chkmax(T1 &x, T2 y) { if (x < y) x = y; } 
const string FILENAME = "input";
const int MAXN = 500228;


int n;
vector<int> mod;
vector<int> d;
int ss;
int where[MAXN * 2];


inline void push(const int &v) {
	if (mod[v]) {
		d[v] += mod[v];
		if (v < ss) {
			mod[v << 1] += mod[v];
			mod[(v << 1) + 1] += mod[v];
		}
		mod[v] = 0;
	}
}


void add(int v, int vl, int vr, const int &l, const int &r, const int &x) {
	if (vl > r || vr < l) {
		push(v);
		return;
	}
	if (l <= vl && vr <= r) {
		mod[v] += x;
		push(v);
		return;
	}
	push(v);
	int vn = v << 1;
	int vm = (vl + vr) >> 1; 
	add(vn, vl, vm, l, r, x);
	add(vn + 1, vm + 1, vr, l, r, x);
	d[v] = max(d[vn], d[vn + 1]);
}


int border[MAXN];
int a[MAXN];
	vector<pair<int, int> > st;

void add(int val) {
	add(1, 1, ss, where[val], where[val], 1000000000);
	add(1, 1, ss, border[where[val] - 1] + 1, sz(st), -1);
}


void del(int val) {
	add(1, 1, ss, where[val], where[val], -1000000000);
	add(1, 1, ss, border[where[val] - 1] + 1, sz(st), 1);
}


vector<int> countScans(vector<int> A,vector<int> X,vector<int> V){
	n = sz(A);
	for (int i = 0; i < n; i++) {
		st.pb({A[i], i});
		a[i] = i;
	}
	for (int i = 0; i < sz(X); i++) {
		st.pb({V[i], n + i});
	}
	sort(all(st));
	ss = 1;
	while (ss < sz(st)) {
		ss <<= 1;
	}
	d.resize(2 * ss);
	mod.resize(2 * ss);
	for (int i = 0; i < sz(st); i++) {
		where[st[i].second] = i + 1;
		add(1, 1, ss, i + 1, i + 1, -1000000000 + (st[i].second >= n ? X[st[i].second - n]: st[i].second) + 1);
	}
	int uk = sz(st);
	for (int i = sz(st) - 1; i >= 0; i--) {
		while (uk - 1 >= 0 && st[uk - 1].first >= st[i].first) {
			uk--;
		}
		border[i] = uk;
	}	
	for (int i = 0; i < n; i++) {
		add(a[i]);
	}
	vector<int> answer;
	for (int i = 0; i < sz(X); i++) {
		del(a[X[i]]);
		a[X[i]] = n + i;
		add(a[X[i]]);
		answer.pb(d[1] + mod[1]);
	}
	return answer;
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 376 KB Output is correct
2 Correct 5 ms 484 KB Output is correct
3 Correct 8 ms 792 KB Output is correct
4 Correct 8 ms 792 KB Output is correct
5 Correct 9 ms 792 KB Output is correct
6 Correct 9 ms 792 KB Output is correct
7 Correct 7 ms 792 KB Output is correct
8 Correct 9 ms 792 KB Output is correct
9 Correct 9 ms 852 KB Output is correct
10 Correct 8 ms 852 KB Output is correct
11 Correct 10 ms 852 KB Output is correct
12 Correct 9 ms 852 KB Output is correct
13 Correct 9 ms 852 KB Output is correct
14 Correct 7 ms 852 KB Output is correct
15 Correct 10 ms 852 KB Output is correct
16 Correct 7 ms 852 KB Output is correct
17 Correct 8 ms 868 KB Output is correct
18 Correct 9 ms 868 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 376 KB Output is correct
2 Correct 5 ms 484 KB Output is correct
3 Correct 8 ms 792 KB Output is correct
4 Correct 8 ms 792 KB Output is correct
5 Correct 9 ms 792 KB Output is correct
6 Correct 9 ms 792 KB Output is correct
7 Correct 7 ms 792 KB Output is correct
8 Correct 9 ms 792 KB Output is correct
9 Correct 9 ms 852 KB Output is correct
10 Correct 8 ms 852 KB Output is correct
11 Correct 10 ms 852 KB Output is correct
12 Correct 9 ms 852 KB Output is correct
13 Correct 9 ms 852 KB Output is correct
14 Correct 7 ms 852 KB Output is correct
15 Correct 10 ms 852 KB Output is correct
16 Correct 7 ms 852 KB Output is correct
17 Correct 8 ms 868 KB Output is correct
18 Correct 9 ms 868 KB Output is correct
19 Correct 35 ms 1468 KB Output is correct
20 Correct 26 ms 1468 KB Output is correct
21 Correct 34 ms 1472 KB Output is correct
22 Correct 39 ms 1512 KB Output is correct
23 Correct 30 ms 1512 KB Output is correct
24 Correct 26 ms 1512 KB Output is correct
25 Correct 32 ms 1512 KB Output is correct
26 Correct 25 ms 1512 KB Output is correct
27 Correct 29 ms 1512 KB Output is correct
28 Correct 24 ms 1556 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 50 ms 2216 KB Output is correct
2 Correct 150 ms 3768 KB Output is correct
3 Correct 252 ms 6176 KB Output is correct
4 Correct 231 ms 6176 KB Output is correct
5 Correct 236 ms 6220 KB Output is correct
6 Correct 239 ms 6220 KB Output is correct
7 Correct 249 ms 6220 KB Output is correct
8 Correct 227 ms 6248 KB Output is correct
9 Correct 193 ms 6248 KB Output is correct
10 Correct 182 ms 6248 KB Output is correct
11 Correct 175 ms 6340 KB Output is correct
12 Correct 181 ms 6340 KB Output is correct
13 Correct 186 ms 6340 KB Output is correct
14 Correct 266 ms 6340 KB Output is correct
15 Correct 219 ms 6340 KB Output is correct
16 Correct 216 ms 6340 KB Output is correct
17 Correct 183 ms 6340 KB Output is correct
18 Correct 186 ms 6340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 376 KB Output is correct
2 Correct 5 ms 484 KB Output is correct
3 Correct 8 ms 792 KB Output is correct
4 Correct 8 ms 792 KB Output is correct
5 Correct 9 ms 792 KB Output is correct
6 Correct 9 ms 792 KB Output is correct
7 Correct 7 ms 792 KB Output is correct
8 Correct 9 ms 792 KB Output is correct
9 Correct 9 ms 852 KB Output is correct
10 Correct 8 ms 852 KB Output is correct
11 Correct 10 ms 852 KB Output is correct
12 Correct 9 ms 852 KB Output is correct
13 Correct 9 ms 852 KB Output is correct
14 Correct 7 ms 852 KB Output is correct
15 Correct 10 ms 852 KB Output is correct
16 Correct 7 ms 852 KB Output is correct
17 Correct 8 ms 868 KB Output is correct
18 Correct 9 ms 868 KB Output is correct
19 Correct 35 ms 1468 KB Output is correct
20 Correct 26 ms 1468 KB Output is correct
21 Correct 34 ms 1472 KB Output is correct
22 Correct 39 ms 1512 KB Output is correct
23 Correct 30 ms 1512 KB Output is correct
24 Correct 26 ms 1512 KB Output is correct
25 Correct 32 ms 1512 KB Output is correct
26 Correct 25 ms 1512 KB Output is correct
27 Correct 29 ms 1512 KB Output is correct
28 Correct 24 ms 1556 KB Output is correct
29 Correct 50 ms 2216 KB Output is correct
30 Correct 150 ms 3768 KB Output is correct
31 Correct 252 ms 6176 KB Output is correct
32 Correct 231 ms 6176 KB Output is correct
33 Correct 236 ms 6220 KB Output is correct
34 Correct 239 ms 6220 KB Output is correct
35 Correct 249 ms 6220 KB Output is correct
36 Correct 227 ms 6248 KB Output is correct
37 Correct 193 ms 6248 KB Output is correct
38 Correct 182 ms 6248 KB Output is correct
39 Correct 175 ms 6340 KB Output is correct
40 Correct 181 ms 6340 KB Output is correct
41 Correct 186 ms 6340 KB Output is correct
42 Correct 266 ms 6340 KB Output is correct
43 Correct 219 ms 6340 KB Output is correct
44 Correct 216 ms 6340 KB Output is correct
45 Correct 183 ms 6340 KB Output is correct
46 Correct 186 ms 6340 KB Output is correct
47 Correct 1018 ms 19236 KB Output is correct
48 Incorrect 2859 ms 46572 KB Output isn't correct
49 Halted 0 ms 0 KB -