QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#163978#7108. Couleurucup-team1001AC ✓3099ms169248kbC++233.6kb2023-09-04 17:36:402023-09-04 17:36:41

Judging History

你现在查看的是最新测评结果

  • [2023-09-04 17:36:41]
  • 评测
  • 测评结果:AC
  • 用时:3099ms
  • 内存:169248kb
  • [2023-09-04 17:36:40]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define LL __int128
#define irep(i,l,r) for(int i = l; i <= r; ++i)
#define drep(i,l,r) for(int i = r; i >= l; --i)
#define abs(x) (x > 0 ? x : -x)
#define ceil(pp,qq) ((pp>0)^(qq>0)?-abs(pp)/abs(qq):pp%qq?pp/qq+1:pp/qq)
#define floor(pp,qq) ((pp>0)^(qq>0)?-ceil(abs(pp),abs(qq)):pp/qq)
using namespace std;

inline int read(){
	int s=0; bool fl = 0;
	char chcc=getchar();
	while(chcc<'0'||chcc>'9'){if(chcc == '-')fl = 1;chcc = getchar();}
	while(chcc>='0'&&chcc<='9') s=(s<<3)+(s<<1)+(chcc^48),chcc=getchar();
	return fl?-s:s;
}
inline char rc(){
	char readch = getchar();
	while(!('0'<= readch && readch <= '9' || 'A' <= readch && readch <= 'Z' || 'a' <= readch && readch <= 'z'))readch = getchar();
	return readch;
}

const int N = 500999;
const int mod = 1000000007;
const int itinf = 1000000000;
const long long llinf = 100000000000000000;


struct segtree{
	int n, cur, siz;
	vector<array<int,5>>t;
	segtree(){}
	segtree(int maxn){
		n = maxn, cur = 0, siz = 0;
		t.push_back({0,maxn,-1,-1, 0});		
	}
	void init(int maxn){
		n = maxn, cur = 0, siz = 0;
		t.push_back({0,maxn,-1,-1, 0});		
	}
	void insert(int x,int v, int tim){
		if(x == -1)return;
		if(x == 0)siz += tim;
		auto [l,r,ls,rs,sum] = t[x];
		int mid = (l + r) >> 1;
		sum += tim;
		if(l == r){
			t[x] = {l,r,ls,rs,sum};
			return;
		}
		if(v <= mid){
			if(ls == -1){
				t.push_back({l, mid, -1, -1, 0});
				ls = ++ cur;
			}			
			t[x] = {l,r,ls,rs,sum};
			insert(ls, v, tim);
		}
		else{
			if(rs == -1){
				t.push_back({mid + 1, r ,-1, -1, 0});
				rs = ++ cur;
			}
			t[x] = {l,r,ls,rs,sum};
			insert(rs, v, tim);
		}
	}
	int query(int x, int v){
		if(x == -1)return 0;
		auto [l,r,ls,rs,sum] = t[x];	
		int mid = (l + r) >> 1;
		if(v < l)return 0;
		if(v >= r)return sum;
		return query(ls,v) + query(rs, v); 
	}
	segtree operator = (const int& mn){
		segtree tr(mn);
		return tr;	
	}
	void clear(){
		t.clear();
	}
	int size(){
		return siz;
	}
};
struct rg{
	int maxn;
	segtree t;
	ll sum = 0;
	void insert_back(int val){
		t.insert(0, val, 1);
		sum += t.size() - t.query(0, val);
	}
	void insert_front(int val){
		t.insert(0, val, 1);
		sum += t.query(0, val) - 1;
	}
	void del_front(int val){
		sum -= t.query(0, val) - 1;
		t.insert(0, val, -1);
	}
	void del_back(int val){
		sum -= t.size() - t.query(0, val);
		t.insert(0, val, -1);
	}
	int size(){
		return t.size();
	}
	rg(){}
	rg(int mx){
		sum = 0, maxn = mx;
		t.init(maxn);
	}
};
void solve(){
	int n = read();
	ll lstans = 0;
	set<int>st;
	multiset<ll>keys;
	vector<array<int,2>>arr;
	vector<int>a(n + 1);
	vector s(n + 1, rg(n));
	st.insert(-1);
	irep(i,0,n - 1)arr.push_back({read(),i});
	sort(arr.begin(), arr.end());
	irep(i,0,n - 1)a[arr[i][1]] = i;
	irep(i,0,n - 1)s[0].insert_back(a[i]);
	keys.insert(s[0].sum);

	for(int ii = 0; ii < n; ++ii){
		lstans = *(-- keys.end());
		printf("%lld ",lstans);
		int pos = lstans ^ read();
		pos --;
		int l = *(-- st.lower_bound(pos)) + 1, r = l + s[l].size() - 1;
		keys.erase(keys.find(s[l].sum));
		if(s[l].size() < (pos - l) * 2){	
			for(int i = r; i >= pos + 1; --i){
				s[pos + 1].insert_front(a[i]);
				s[l].del_back(a[i]);
			}
			s[l].del_back(a[pos]);
		}else{
			for(int i = l; i <= pos - 1; ++i){
				s[l].del_front(a[i]);
				s[pos + 1].insert_back(a[i]);
			}
			s[l].del_front(a[pos]);
			swap(s[l], s[pos + 1]);
		}
		st.insert(pos);
		keys.insert(s[l].sum);
		if(pos + 1 < n)keys.insert(s[pos + 1].sum);
		
	}
	putchar('\n');
}

int main(){
	int T = read();
	while(T --)solve();
	return 0;
}

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 3828kb

input:

3
5
4 3 1 1 1
5 4 5 3 1
10
9 7 1 4 7 8 5 7 4 8
21 8 15 5 9 2 4 5 10 6
15
4 8 8 1 12 1 10 14 7 14 2 9 13 10 3
37 19 23 15 7 2 10 15 2 13 4 5 8 7 10

output:

7 0 0 0 0 
20 11 7 2 0 0 0 0 0 0 
42 31 21 14 14 4 1 1 1 0 0 0 0 0 0 

result:

ok 3 lines

Test #2:

score: 0
Accepted
time: 3099ms
memory: 169248kb

input:

11116
10
10 5 10 3 6 4 8 5 9 8
31 27 24 11 12 3 0 2 3 1
10
8 2 7 2 8 10 1 10 9 10
6 5 2 13 2 1 0 1 3 1
10
7 10 7 6 1 3 10 6 7 9
21 18 10 1 6 5 4 8 9 10
10
2 10 4 8 8 5 7 2 6 7
20 10 9 1 15 0 4 2 9 7
10
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
10
1 2 3 4 5 6 7 8 9 10
6 3 5 2 7 10 9 1 4 8
10
1 10 1 3...

output:

21 18 16 12 10 6 4 1 1 0 
12 12 10 10 4 4 4 2 1 0 
20 16 9 5 3 3 3 0 0 0 
22 14 8 8 5 5 2 1 1 0 
0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 
19 12 7 4 4 2 2 1 0 0 
20 18 8 3 1 1 0 0 0 0 
45 21 21 10 3 3 3 0 0 0 
17 11 8 2 1 1 1 0 0 0 
13 4 1 0 0 0 0 0 0 0 
29 27 22 15 9 7 4 3 1 0 
26 16 9 2 1 1 1 1 1 ...

result:

ok 11116 lines

Extra Test:

score: 0
Extra Test Passed