답안 #1013513

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1013513 2024-07-03T15:18:02 Z vjudge1 Bubble Sort 2 (JOI18_bubblesort2) C++17
0 / 100
553 ms 8264 KB
// #include "bubblesort2.h"
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define all(v) v.begin(),v.end()
#include <bits/stdc++.h>
using namespace std;
const int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};
#define endl "\n"
using ull=unsigned long long;
using ll=long long;
using pii=pair<int,int>;
const int mod=1e9+7;
#define OVL(x,s) for(auto y:x) cout<<y<<s; cout<<"\n";
template <typename T> istream& operator>>(istream& is, vector<T> &a) {
    copy_n(istream_iterator<T>(is), a.size(), a.begin()); return is;}
#ifdef IOI
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }
 
void dbg_out() { cout << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cout << ' ' << H; dbg_out(T...); }
#define dbg(...) cout << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__);
#else
#define dbg(...) 1337;
#endif
#define pb push_back
#define F first
#define S second
#define all(v) v.begin(),v.end()
const int mxn=2e5+100;
vector<int> a;
int n;
struct Node{
	int val=0;
	int lazy=0;
	Node* left,*right;
	bool islazy=false;
	Node() : left(nullptr),right(nullptr) {}
};
Node* root;
void build(Node* node,int l,int r){
	if(l==r) return;
	int mid=(l+r)/2;
	node->left=new Node();
	node->right=new Node();
	build(node->left,l,mid);
	build(node->right,mid+1,r);
}
void push(Node* node,int l,int r){
	if(!node->islazy) return;
	node->islazy=false;
	node->val+=node->lazy;
	if(l!=r){
		if(node->left) {
			node->left->islazy=true;
			node->left->lazy+=node->lazy;
		}
		if(node->right) {
			node->right->islazy=true;
			node->right->lazy+=node->lazy;
		}
	}
	node->lazy=0;
}
void p(Node* node,int l,int r){
	push(node,l,r);
	int mid=(l+r)/2;
	if(l==r) return;
	if(node->left) push(node->left,l,mid);
	if(node->right) push(node->right,mid+1,r);
}
void update(Node* node,int l,int r,int ql,int qr,int x){
	if(ql>qr) return;
	p(node,l,r);
	// if(ql>r||qr<l) return;
	if(ql<=l&&r<=qr){
		node->islazy=true;
		node->lazy=x;
		// dbg(node->lazy)
		p(node,l,r);
		// dbg(node->val)
		return;
	}
	int mid=(l+r)/2;
	if(ql<=mid) update(node->left,l,mid,ql,qr,x);
	if(qr>mid) update(node->right,mid+1,r,ql,qr,x);
	// p(node,l,r);
	// dbg(l,r)
	// if(!node->left||!node->right) {
	// 	dbg(l,r,ql,qr)
	// 	return;
	// }
	node->val=max(node->left->val,node->right->val);
}

vector<int> countScans(vector<int> A,vector<int> x,vector<int> y){
	a=A;
	root=new Node();
	n=a.size();
	int q=x.size();
	build(root,0,n+q-1);
	vector<pii> v;
	for(int i=0;i<n;i++){
		v.pb({a[i],i});
	}
	for(int i=0;i<q;i++){
		v.pb({y[i],x[i]});
	}
	sort(all(v));
	for(int i=0;i<n;i++){
		a[i]=find(all(v),make_pair(a[i],i))-v.begin();
	}
	for(int i=0;i<q;i++){
		y[i]=find(all(v),make_pair(y[i],x[i]))-v.begin();
	}
	vector<int> Ans(q);
	int sz=n+q;
	for(int i=0;i<n;i++){
		// dbg(a[i])
		update(root,0,sz-1,a[i],a[i],i);
		update(root,0,sz-1,a[i]+1,sz-1,-1);
	}
	// dbg(root->val)
	// dbg("good")
	// return Ans;
	for(int i=0;i<q;i++){
		update(root,0,sz-1,a[x[i]],a[x[i]],-i);
		update(root,0,sz-1,a[x[i]]+1,sz-1,1);
		a[x[i]]=y[i];
		update(root,0,sz-1,a[x[i]],a[x[i]],i);
		update(root,0,sz-1,a[x[i]]+1,sz-1,-1);
		Ans[i]=root->val;
	}
	
	return Ans;
}



#ifdef IOI
// #include "bubblesort2.h"

// #include <cstdio>
// #include <cstdlib>
// #include <vector>

int readInt(){
	int i;
	if(scanf("%d",&i)!=1){
		fprintf(stderr,"Error while reading input\n");
		exit(1);
	}
	return i;
}

int main(){
	int N,Q;
	N=readInt();
	Q=readInt();
	
	vector<int> A(N);
	for(int i=0;i<N;i++)
		A[i]=readInt();
	
	vector<int> X(Q),V(Q);
	for(int j=0;j<Q;j++){
		X[j]=readInt();
		V[j]=readInt();
	}
	
	vector<int> res=countScans(A,X,V);
	
	for(int j=0;j<int(res.size());j++)
		printf("%d\n",res[j]);
}

#endif
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 444 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 444 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 141 ms 3928 KB Output is correct
2 Incorrect 553 ms 8264 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 444 KB Output isn't correct
2 Halted 0 ms 0 KB -