답안 #1081037

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1081037 2024-08-29T17:16:12 Z ten_xd Bubble Sort 2 (JOI18_bubblesort2) C++17
38 / 100
9000 ms 5868 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

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

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();
}

Compilation message

bubblesort2.cpp:11: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
   11 | #pragma GCC optimization ("O3")
      | 
bubblesort2.cpp:12: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
   12 | #pragma GCC optimization ("unroll-loops")
      |
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 4444 KB Output is correct
2 Correct 31 ms 4672 KB Output is correct
3 Correct 247 ms 4808 KB Output is correct
4 Correct 251 ms 4700 KB Output is correct
5 Correct 274 ms 4700 KB Output is correct
6 Correct 256 ms 4952 KB Output is correct
7 Correct 255 ms 4700 KB Output is correct
8 Correct 253 ms 4696 KB Output is correct
9 Correct 244 ms 4696 KB Output is correct
10 Correct 270 ms 4788 KB Output is correct
11 Correct 265 ms 4700 KB Output is correct
12 Correct 263 ms 4784 KB Output is correct
13 Correct 258 ms 4700 KB Output is correct
14 Correct 272 ms 4696 KB Output is correct
15 Correct 267 ms 4696 KB Output is correct
16 Correct 262 ms 4756 KB Output is correct
17 Correct 264 ms 4700 KB Output is correct
18 Correct 273 ms 4700 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 4444 KB Output is correct
2 Correct 31 ms 4672 KB Output is correct
3 Correct 247 ms 4808 KB Output is correct
4 Correct 251 ms 4700 KB Output is correct
5 Correct 274 ms 4700 KB Output is correct
6 Correct 256 ms 4952 KB Output is correct
7 Correct 255 ms 4700 KB Output is correct
8 Correct 253 ms 4696 KB Output is correct
9 Correct 244 ms 4696 KB Output is correct
10 Correct 270 ms 4788 KB Output is correct
11 Correct 265 ms 4700 KB Output is correct
12 Correct 263 ms 4784 KB Output is correct
13 Correct 258 ms 4700 KB Output is correct
14 Correct 272 ms 4696 KB Output is correct
15 Correct 267 ms 4696 KB Output is correct
16 Correct 262 ms 4756 KB Output is correct
17 Correct 264 ms 4700 KB Output is correct
18 Correct 273 ms 4700 KB Output is correct
19 Correct 4155 ms 5716 KB Output is correct
20 Correct 5388 ms 5704 KB Output is correct
21 Correct 5092 ms 5716 KB Output is correct
22 Correct 5176 ms 5712 KB Output is correct
23 Correct 5253 ms 5716 KB Output is correct
24 Correct 5238 ms 5564 KB Output is correct
25 Correct 5231 ms 5512 KB Output is correct
26 Correct 5263 ms 5464 KB Output is correct
27 Correct 5230 ms 5464 KB Output is correct
28 Correct 5293 ms 5468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3798 ms 5308 KB Output is correct
2 Execution timed out 9064 ms 5868 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 4444 KB Output is correct
2 Correct 31 ms 4672 KB Output is correct
3 Correct 247 ms 4808 KB Output is correct
4 Correct 251 ms 4700 KB Output is correct
5 Correct 274 ms 4700 KB Output is correct
6 Correct 256 ms 4952 KB Output is correct
7 Correct 255 ms 4700 KB Output is correct
8 Correct 253 ms 4696 KB Output is correct
9 Correct 244 ms 4696 KB Output is correct
10 Correct 270 ms 4788 KB Output is correct
11 Correct 265 ms 4700 KB Output is correct
12 Correct 263 ms 4784 KB Output is correct
13 Correct 258 ms 4700 KB Output is correct
14 Correct 272 ms 4696 KB Output is correct
15 Correct 267 ms 4696 KB Output is correct
16 Correct 262 ms 4756 KB Output is correct
17 Correct 264 ms 4700 KB Output is correct
18 Correct 273 ms 4700 KB Output is correct
19 Correct 4155 ms 5716 KB Output is correct
20 Correct 5388 ms 5704 KB Output is correct
21 Correct 5092 ms 5716 KB Output is correct
22 Correct 5176 ms 5712 KB Output is correct
23 Correct 5253 ms 5716 KB Output is correct
24 Correct 5238 ms 5564 KB Output is correct
25 Correct 5231 ms 5512 KB Output is correct
26 Correct 5263 ms 5464 KB Output is correct
27 Correct 5230 ms 5464 KB Output is correct
28 Correct 5293 ms 5468 KB Output is correct
29 Correct 3798 ms 5308 KB Output is correct
30 Execution timed out 9064 ms 5868 KB Time limit exceeded
31 Halted 0 ms 0 KB -