답안 #852000

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
852000 2023-09-21T05:11:53 Z MrM7md Bubble Sort 2 (JOI18_bubblesort2) C++17
0 / 100
28 ms 73560 KB
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
// #define int long long
#define F first
#define S second
#define pb push_back
#define all(a) a.begin(),a.end()
const int N=2e5 + 3;
const int MOD=1e9+7;
const int off=(1<<20);
 
int t[off*2],dis[off*2],lazy[off*2];
void upd2(int x,int v){
	x+=off;
	t[x]+=v;
	while(x/=2){
		t[x]=t[x*2]+t[x*2+1];
	}
}
int get2(int x,int l,int r,int st,int en){
	if(r<st||l>en)return 0;
	if(r<=en&&l>=st){
		return t[x];
	}
	int md=(l+r)/2;
	return get2(x*2,l,md,st,en)+get2(x*2+1,md+1,r,st,en);
}
void push(int x,int l,int r){
   if(lazy[x]==0)return;
   if(l!=r){
      lazy[x*2]+=lazy[x];
      lazy[x*2+1]+=lazy[x];
   }
   dis[x]+=lazy[x];
   lazy[x]=0;
}
void upd(int x,int l,int r,int st,int en,int df){
   push(x,l,r);
   if(r<st||l>en)return ;
   if(l>=st&&r<=en){
      lazy[x]+=df;
      push(x,l,r);
      return ;
   }
   int md=(l+r)/2;
   upd(x*2,l,md,st,en,df);
   upd(x*2+1,md+1,r,st,en,df);
   dis[x]=max(dis[x*2],dis[x*2+1]);

}
int get(int x,int l,int r,int st,int en){
   push(x,l,r);
   if(r<st||l>en)return INT_MIN;
   if(l>=st&&r<=en){
      return dis[x];
   }
   int md=(l+r)/2;
   int ll=get(x*2,l,md,st,en);
   int rr=get(x*2+1,md+1,r,st,en);
   return max(ll,rr);
}

 
std::vector<int> countScans(std::vector<int> A,std::vector<int> X,std::vector<int> V){
	for(int i=0;i<off*2;i++)dis[i]=INT_MIN,t[i]=0,lazy[i]=0;
	int q=X.size(),n=A.size();
	vector<int>ans;
	set<int>st;
	for(auto it:A)st.insert(it);
	for(auto it:V)st.insert(it);
	int cnt=1;
	map<int,int>mp;
	for(auto it:st)mp[it]=cnt++;
	vector<set<int>>vv(1e6+20);
	for(int i=0;i<n;i++){
		int a=A[i];
		upd2(mp[a],1);
		vv[mp[a]].insert(i+1);
	}
	int cur=0;
	for(int i=1;i<=cnt;i++){
		if(vv[i].empty()){
			// upd(1,1,off-1,i+1,i+1,INT_MIN);
			continue;
		}
		cur+=vv[i].size();
		upd(1,1,off-1,i+1,i+1,(-1*dis[i+off])+(*vv[i].rbegin())-cur);
	}
	for(int j=0;j<q;j++){
		int x=X[j],v=mp[V[j]];
		int a=mp[A[x]],prev;
		// upd(1,1,off-1,a+1,cnt+1,-1);
		upd(1,1,off-1,v+1,cnt+1,1);
		upd(1,1,off-1,a+1,a+1,-1*dis[a+off]);

		upd2(a,-1);
		vv[a].erase(x+1);
		vv[v].insert(x+1);
		upd2(v,1);

		prev=get2(1,1,off-1,1,v+1);
		// cout<<prev<<' ';
		upd(1,1,off-1,v+1,v+1,-1*dis[v+off]);
		upd(1,1,off-1,v+1,v+1,(*vv[v].rbegin())-prev);
		cout<<dis[1]<<endl;
		if(vv[a].size()&&a!=v){
			prev=get2(1,1,off-1,1,a+1);
			upd(1,1,off-1,a+1,a+1,(*vv[a].rbegin())-prev);
		}
		A[x]=V[j];
		// ans.pb(dis[1]);
		ans.pb(dis[1]);
	}
	return ans;

}

/*


1 2 5 7 3 5 4







*/
# 결과 실행 시간 메모리 Grader output
1 Incorrect 15 ms 72028 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 15 ms 72028 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 28 ms 73560 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 15 ms 72028 KB Output isn't correct
2 Halted 0 ms 0 KB -