답안 #408771

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
408771 2021-05-19T15:41:15 Z AmineWeslati Bubble Sort 2 (JOI18_bubblesort2) C++14
0 / 100
9000 ms 4428 KB
#include <bits/stdc++.h>
#include "bubblesort2.h"
using namespace std;

typedef long long ll;
typedef vector<int>vi;
#define pb push_back
#define sz(v) (int)v.size()
#define all(x) begin(x),end(x)

#define FOR(i,a,b) for(int i=a; i<b; i++)
#define ROF(i,a,b) for(int i=b-1; i>=a; i--)

//--------------------------------------------//

int N,Q;
vi a; 

const int MX=5e5+10;

void ckmax(int &x, int y){x=max(x,y);}


vi t(MX,0);
void upd(int idx){
	int i=idx; 
	for(;i<=N; i+=i&-i){
		t[i]++;
	}
}

int get(int idx){
	int i=idx; 
	int ans=0;
	for(;i;i-=i&-i) ans+=t[i];
	return ans;
}

vi countScans(vi A,vi X,vi V){
	N=sz(A); Q=sz(X);
	a.assign(all(A));

	vi temp;
	temp.assign(all(a));
	sort(all(temp));

	int cnt=0;
	unordered_map<int,int>mp;
	for(int x: temp) if(!mp.count(x)) mp[x]=++cnt; 
	FOR(i,0,N) a[i]=mp[a[i]];


	vi ans(Q);
	FOR(idx,0,Q){
		a[X[idx]]=V[idx];

		vi st,vec(N);
		ROF(i,0,N){
			while(sz(st) && st.back()<a[i]) st.pop_back();

			if(!sz(st)){
				vec[i]=(i!=N-1);
			} 
			else{
				if(st.back()==i+1 && !vec[st.back()])
					vec[i]=0;
				else vec[i]=vec[st.back()]+1;
			}

			st.pb(i);
		}
		
		t.assign(N+10,0);
		FOR(i,0,N){
			ckmax(vec[i],i-get(a[i]));
			upd(a[i]);
		}

		ans[idx]=0;
		FOR(i,0,N) ckmax(ans[idx],vec[i]);

	}
	return ans; 
}

/*

4 2
1 2 3 4
0 3
2 1

*/
# 결과 실행 시간 메모리 Grader output
1 Runtime error 4 ms 4428 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 4 ms 4428 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2542 ms 3440 KB Output is correct
2 Execution timed out 9084 ms 4352 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 4 ms 4428 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -