Submission #1081036

# Submission time Handle Problem Language Result Execution time Memory
1081036 2024-08-29T17:14:39 Z ten_xd Bubble Sort 2 (JOI18_bubblesort2) C++17
38 / 100
9000 ms 6100 KB
#include "bubblesort2.h"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define rep(a,b) for(int a = 0; a < (b); ++a)
#define all(t) t.begin(), t.end()
#define pb push_back

const int N = 5e5+5, INF = 2e9+54321;
const ull INF_L = (ll)2e18+54321;

int n,q,base,rozmiar_drzewa;
int B[N], XX[N], YY[N];
vector<int> tree;

void update(int v)
{
	v += base, tree[v] += 1, v /= 2;
	while(v > 0) tree[v] = tree[v*2] + tree[v*2+1], v /= 2;
}

int query(int l, int p)
{
	l = l + base - 1, p = p + base + 1;
	int res = 0;
	while(l/2 != p/2)
	{
		if(l % 2 == 0) res += tree[l+1];
		if(p % 2 == 1) res += tree[p-1];
		l /= 2, p /= 2;
	}
	return res;
}

vector<int> solve()
{
	vector<int> res;
	map<int,int> M;
	rep(i,n) M[B[i]] = -1;
	rep(i,q) M[YY[i]] = -1;
	int cnt = -1;
	for(auto it = M.begin(); it != M.end(); ++it) it->second = ++cnt;

	base = 1;
	while(base <= n+q+50) base *= 2;
	rozmiar_drzewa = base * 2;

	rep(i,n) B[i] = M[B[i]];
	rep(z,q)
	{
		B[XX[z]] = M[YY[z]];
		tree.assign(rozmiar_drzewa,0);

		int wyn = 0;

		rep(i,n)
		{
			wyn = max(wyn,query(B[i]+1,n+q+3));
			update(B[i]);
		}

		res.pb(wyn);
	}

	return res;
}

std::vector<int> countScans(std::vector<int> A,std::vector<int> X,std::vector<int> V)
{
	n = (int)A.size(), q = (int)X.size();
	rep(i,n) B[i] = A[i];
	rep(i,q) XX[i] = X[i], YY[i] = V[i];

	return solve();
}
# Verdict Execution time Memory Grader output
1 Correct 15 ms 4444 KB Output is correct
2 Correct 32 ms 4444 KB Output is correct
3 Correct 255 ms 4700 KB Output is correct
4 Correct 252 ms 4868 KB Output is correct
5 Correct 257 ms 4852 KB Output is correct
6 Correct 264 ms 4700 KB Output is correct
7 Correct 250 ms 4696 KB Output is correct
8 Correct 263 ms 4700 KB Output is correct
9 Correct 249 ms 4700 KB Output is correct
10 Correct 262 ms 4696 KB Output is correct
11 Correct 265 ms 4696 KB Output is correct
12 Correct 271 ms 4836 KB Output is correct
13 Correct 269 ms 4808 KB Output is correct
14 Correct 270 ms 5068 KB Output is correct
15 Correct 266 ms 4696 KB Output is correct
16 Correct 266 ms 4952 KB Output is correct
17 Correct 267 ms 4804 KB Output is correct
18 Correct 272 ms 4812 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 4444 KB Output is correct
2 Correct 32 ms 4444 KB Output is correct
3 Correct 255 ms 4700 KB Output is correct
4 Correct 252 ms 4868 KB Output is correct
5 Correct 257 ms 4852 KB Output is correct
6 Correct 264 ms 4700 KB Output is correct
7 Correct 250 ms 4696 KB Output is correct
8 Correct 263 ms 4700 KB Output is correct
9 Correct 249 ms 4700 KB Output is correct
10 Correct 262 ms 4696 KB Output is correct
11 Correct 265 ms 4696 KB Output is correct
12 Correct 271 ms 4836 KB Output is correct
13 Correct 269 ms 4808 KB Output is correct
14 Correct 270 ms 5068 KB Output is correct
15 Correct 266 ms 4696 KB Output is correct
16 Correct 266 ms 4952 KB Output is correct
17 Correct 267 ms 4804 KB Output is correct
18 Correct 272 ms 4812 KB Output is correct
19 Correct 4320 ms 5712 KB Output is correct
20 Correct 5452 ms 5700 KB Output is correct
21 Correct 5150 ms 5968 KB Output is correct
22 Correct 5308 ms 6100 KB Output is correct
23 Correct 5327 ms 5724 KB Output is correct
24 Correct 5365 ms 5724 KB Output is correct
25 Correct 5373 ms 5716 KB Output is correct
26 Correct 5414 ms 5724 KB Output is correct
27 Correct 5418 ms 5716 KB Output is correct
28 Correct 5358 ms 5468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3904 ms 5160 KB Output is correct
2 Execution timed out 9037 ms 5980 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 15 ms 4444 KB Output is correct
2 Correct 32 ms 4444 KB Output is correct
3 Correct 255 ms 4700 KB Output is correct
4 Correct 252 ms 4868 KB Output is correct
5 Correct 257 ms 4852 KB Output is correct
6 Correct 264 ms 4700 KB Output is correct
7 Correct 250 ms 4696 KB Output is correct
8 Correct 263 ms 4700 KB Output is correct
9 Correct 249 ms 4700 KB Output is correct
10 Correct 262 ms 4696 KB Output is correct
11 Correct 265 ms 4696 KB Output is correct
12 Correct 271 ms 4836 KB Output is correct
13 Correct 269 ms 4808 KB Output is correct
14 Correct 270 ms 5068 KB Output is correct
15 Correct 266 ms 4696 KB Output is correct
16 Correct 266 ms 4952 KB Output is correct
17 Correct 267 ms 4804 KB Output is correct
18 Correct 272 ms 4812 KB Output is correct
19 Correct 4320 ms 5712 KB Output is correct
20 Correct 5452 ms 5700 KB Output is correct
21 Correct 5150 ms 5968 KB Output is correct
22 Correct 5308 ms 6100 KB Output is correct
23 Correct 5327 ms 5724 KB Output is correct
24 Correct 5365 ms 5724 KB Output is correct
25 Correct 5373 ms 5716 KB Output is correct
26 Correct 5414 ms 5724 KB Output is correct
27 Correct 5418 ms 5716 KB Output is correct
28 Correct 5358 ms 5468 KB Output is correct
29 Correct 3904 ms 5160 KB Output is correct
30 Execution timed out 9037 ms 5980 KB Time limit exceeded
31 Halted 0 ms 0 KB -