QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#160764#7108. Couleurucup-team134#AC ✓3285ms28728kbC++145.5kb2023-09-02 21:21:182023-09-02 21:21:19

Judging History

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

  • [2023-09-02 21:21:19]
  • 评测
  • 测评结果:AC
  • 用时:3285ms
  • 内存:28728kb
  • [2023-09-02 21:21:18]
  • 提交

answer

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>

#define ll long long
#define pb push_back
#define f first
#define s second
#define sz(x) (int)(x).size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define ios ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ld long double
#define li __int128

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>; ///find_by_order(),order_of_key()
template<int D, typename T>struct vec : public vector<vec<D - 1, T>> {template<typename... Args>vec(int n = 0, Args... args) : vector<vec<D - 1, T>>(n, vec<D - 1, T>(args...)) {}};
template<typename T>struct vec<1, T> : public vector<T> {vec(int n = 0, T val = T()) : vector<T>(n, val) {}};
template<class T1,class T2> ostream& operator<<(ostream& os, const pair<T1,T2>& a) { os << '{' << a.f << ", " << a.s << '}'; return os; }
template<class T> ostream& operator<<(ostream& os, const vector<T>& a){os << '{';for(int i=0;i<sz(a);i++){if(i>0&&i<sz(a))os << ", ";os << a[i];}os<<'}';return os;}
template<class T> ostream& operator<<(ostream& os, const deque<T>& a){os << '{';for(int i=0;i<sz(a);i++){if(i>0&&i<sz(a))os << ", ";os << a[i];}os<<'}';return os;}
template<class T> ostream& operator<<(ostream& os, const set<T>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
template<class T> ostream& operator<<(ostream& os, const set<T,greater<T> >& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
template<class T> ostream& operator<<(ostream& os, const multiset<T>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
template<class T> ostream& operator<<(ostream& os, const multiset<T,greater<T> >& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
template<class T1,class T2> ostream& operator<<(ostream& os, const map<T1,T2>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
int ri(){int x;scanf("%i",&x);return x;}
void rd(int&x){scanf("%i",&x);}
void rd(long long&x){scanf("%lld",&x);}
void rd(double&x){scanf("%lf",&x);}
void rd(long double&x){scanf("%Lf",&x);}
void rd(string&x){cin>>x;}
void rd(char*x){scanf("%s",x);}
template<typename T1,typename T2>void rd(pair<T1,T2>&x){rd(x.first);rd(x.second);}
template<typename T>void rd(vector<T>&x){for(T&p:x)rd(p);}
template<typename C,typename...T>void rd(C&a,T&...args){rd(a);rd(args...);}
//istream& operator>>(istream& is,__int128& a){string s;is>>s;a=0;int i=0;bool neg=false;if(s[0]=='-')neg=true,i++;for(;i<s.size();i++)a=a*10+s[i]-'0';if(neg)a*=-1;return is;}
//ostream& operator<<(ostream& os,__int128 a){bool neg=false;if(a<0)neg=true,a*=-1;ll high=(a/(__int128)1e18);ll low=(a-(__int128)1e18*high);string res;if(neg)res+='-';if(high>0){res+=to_string(high);string temp=to_string(low);res+=string(18-temp.size(),'0');res+=temp;}else res+=to_string(low);os<<res;return os;}

void test(){
	int n=ri();
	vector<int> a(n);
	rd(a);
	set<pair<pair<int,int>,int>> in;
	vector<pair<ordered_set<pair<int,int>>,ll>> sets;
	in.insert({{0,n-1},0});
	multiset<ll> cnts;
	ll cnt=0;
	ordered_set<pair<int,int>> st;
	for(int i=0;i<n;i++){
		cnt+=sz(st)-st.order_of_key({a[i]+1,-1});
		st.insert({a[i],i});
	}
	sets.pb({st,cnt});
	cnts.insert(cnt);
	for(int i=0;i<n;i++){
		ll br=*cnts.rbegin();
		printf("%lld",br);
		if(i!=n-1){
			printf(" ");
		}
		/*for(auto p:sets){
			printf("[");
			for(auto d:p.f){
				printf("(%i %i) ",d.f,d.s);
			}
			printf("], %lld\n",p.s);
		}*/
		ll p;
		rd(p);
		p^=br;
		p--;
		//printf("Brisem %i\n",p);
		auto it=in.lower_bound({{p,n},n});
		it--;
		int l=(*it).f.f,r=(*it).f.s,ind=(*it).s;
		in.erase(it);
		//printf("%i %i %i %i\n",l,r,ind,p);
		int levi=p-l,desni=r-p;
		cnts.erase(cnts.find(sets[ind].s));
		if(levi<desni){
			for(int i=l;i<=p;i++){
				sets[ind].f.erase({a[i],i});
			}
			for(int i=l;i<=p;i++){
				sets[ind].s-=sets[ind].f.order_of_key({a[i],-1});
			}
			if(l!=p){
				int newInd=sz(sets);
				ordered_set<pair<int,int>> novi;
				ll noviCnt=0;
				for(int i=l;i<p;i++){
					noviCnt+=sz(novi)-novi.order_of_key({a[i]+1,-1});
					novi.insert({a[i],i});
				}
				sets[ind].s-=noviCnt;
				cnts.insert(noviCnt);
				cnt+=noviCnt;
				sets[ind].s-=sz(novi)-novi.order_of_key({a[p]+1,-1});
				sets.pb({novi,noviCnt});
				in.insert({{l,p-1},newInd});
			}
			if(r!=p){
				in.insert({{p+1,r},ind});
				cnts.insert(sets[ind].s);
			}
		}
		else{
			for(int i=p;i<=r;i++){
				sets[ind].f.erase({a[i],i});
			}
			for(int i=p;i<=r;i++){
				sets[ind].s-=sz(sets[ind].f)-sets[ind].f.order_of_key({a[i]+1,-1});
			}
			if(r!=p){
				int newInd=sz(sets);
				ordered_set<pair<int,int>> novi;
				ll noviCnt=0;
				for(int i=p+1;i<=r;i++){
					noviCnt+=(int)novi.size()-novi.order_of_key({a[i]+1,-1});
					novi.insert({a[i],i});
				}
				sets[ind].s-=noviCnt;
				cnts.insert(noviCnt);
				sets[ind].s-=novi.order_of_key({a[p],-1});
				sets.pb({novi,noviCnt});
				in.insert({{p+1,r},newInd});
			}
			if(l!=p) {
				in.insert({{l,p-1},ind});
				cnts.insert(sets[ind].s);
			}
		}
	}
	printf("\n");
}
int main()
{
	int t=ri();
	while(t--){
		test();
	}
	return 0;
}

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3996kb

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: 3285ms
memory: 28728kb

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 0
0 0 0 0 0 ...

result:

ok 11116 lines

Extra Test:

score: 0
Extra Test Passed