QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#697688#5308. RPG Pro LeaguexzzduangWA 159ms13508kbC++234.2kb2024-11-01 15:21:162024-11-01 15:21:17

Judging History

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

  • [2024-11-01 15:21:17]
  • 评测
  • 测评结果:WA
  • 用时:159ms
  • 内存:13508kb
  • [2024-11-01 15:21:16]
  • 提交

answer

#include<iostream>
#include<stdio.h>
#include<ctype.h>
#include<string.h>
#include<set>
#include<queue>
#include<algorithm>
#define ll long long
#define ld long double
#define int long long
#define fi first
#define se second
#define pii pair<int,int>
#define lowbit(x) ((x)&-(x))
#define popcount(x) __builtin_popcount(x)
#define inf 0x3f3f3f3f
#define infll 0x3f3f3f3f3f3f3f3f
#define umap unordered_map
#define all(x) x.begin(),x.end()
#define mk make_pair
#define pb push_back
#define ckmax(x,y) x=max(x,y)
#define ckmin(x,y) x=min(x,y)
#define rep(i,l,r) for(int i=l;i<=r;++i)
#define per(i,r,l) for(int i=r;i>=l;--i)
using namespace std;
inline int read(){
	int x=0,f=0; char ch=getchar();
	while(!isdigit(ch)) f|=(ch==45),ch=getchar();
	while(isdigit(ch)) x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
	return f?-x:x;
}
#define N 100005
struct edge{
	int b,c,n;
}e[1000];
ll ans;
int n,cnt[100],T=20,h[1000],tot=1,id[N],team,is[N];
pii a[N];
char s[10];
set<pii> ed[16],un[16];
inline void charu(int a,int b,int c){
	e[++tot].b=b,e[tot].c=c,e[tot].n=h[a],h[a]=tot;
	e[++tot].b=a,e[tot].c=0,e[tot].n=h[b],h[b]=tot;
}
inline bool check(int t){
	for(int j=0;j<16;++j){
		int x=0;
		for(int i=0;i<16;++i){
			if(i&j) x+=cnt[i];
		}
		if(x<t*popcount(j)) return false;
	}
	return true;
}
inline bool cmp(int x,int y){
	return a[x].fi<a[y].fi;
}
queue<int> q;
int vis[25],pre[25];
inline void bfs(int L,int tag){
	while(!q.empty()) q.pop();
	memset(vis,0,sizeof(vis));
	vis[L]=1,q.push(L);
	while(!q.empty()){
		int u=q.front();q.pop();
		for(int i=h[u];i;i=e[i].n){
			int v=e[i].b;
			if((tag&&e[i].c&&!vis[v]) || (!tag&&e[i^1].c&&!vis[v])){
				vis[v]=1,pre[v]=i;
				q.push(v);
			}
		}
	}
}
inline bool augment(int L){
	bfs(L,1);
	if(!vis[T]) return false;
	for(int x=T;x!=L;x=e[pre[x]^1].b) e[pre[x]].c--,e[pre[x]^1].c++;
	return true;
}
signed main(){
	n=read();
	for(int i=1;i<=n;++i){
		scanf("%s",s+1);
		a[i].fi=read();
		int l=strlen(s+1);
		for(int j=1;j<=l;++j){
			if(s[j]=='D'){
				a[i].se|=1;
				a[i].se|=8;
			}
			if(s[j]=='S'){
				a[i].se|=2;
				a[i].se|=8;
			}
			if(s[j]=='B'){
				a[i].se|=4;
			}
		}
		id[i]=i;
	}
	for(int i=1;i<=n;++i){
		cnt[a[i].se]++;
	}
	int l=1,r=n;
	while(l<=r){
		int mid=l+r>>1;
		if(check(mid)) l=mid+1;
		else r=mid-1;
	}
	team=r;
	for(int i=0;i<16;++i){
		for(int j=0;j<4;++j){
			if(i&(1<<j)) charu(i,j+16,inf);
		}
	}
	for(int j=0;j<4;++j) charu(j+16,T,team);
	sort(id+1,id+n+1,cmp);
	for(int i=1;i<=n;++i){
		if(augment(a[id[i]].se)){
			ed[a[id[i]].se].insert({a[id[i]].fi,id[i]});
			ans+=a[id[i]].fi;
			is[id[i]]=1;
		}
		else{
			un[a[id[i]].se].insert({a[id[i]].fi,id[i]});
		}
	}
	for(int cas=read();cas--;){
		int x=read(),y=read();
		if(is[x]){
			ans+=y-a[x].fi;
			ed[a[x].se].erase({a[x].fi,x});
			ed[a[x].se].insert({y,x});
			swap(a[x].fi,y);
			if(y<a[x].fi){
				bfs(a[x].se,0);
				int res=x;
				for(int i=0;i<16;++i){
					if(un[i].empty()) continue;
					auto it=un[i].begin();
					if(vis[i] && (it->fi)<a[res].fi){
						res=it->se;
					}
				}
				if(res!=x){
					ans+=a[res].fi-a[x].fi;
					is[x]=0;
					ed[a[x].se].erase({a[x].fi,x});
					un[a[x].se].insert({a[x].fi,x});
					is[res]=1;
					un[a[res].se].erase({a[res].fi,res});
					ed[a[res].se].insert({a[res].fi,res});
					for(int t=a[res].se;t!=a[x].se;t=e[pre[t]^1].b){
						e[pre[t]].c++,e[pre[t]^1].c--;
					}
				}
			}
		}
		else{
			un[a[x].se].erase({a[x].fi,x});
			un[a[x].se].insert({y,x});
			swap(a[x].fi,y);
			if(y>a[x].fi){
				bfs(a[x].se,1);
				int res=x;
				for(int i=0;i<16;++i){
					if(ed[i].empty()) continue;
					auto it=ed[i].end();it--;
					if(vis[i] && (it->fi)>a[res].fi){
						res=it->se;
					}
				}
				if(res!=x){
					ans+=a[x].fi-a[res].fi;
					is[res]=0;
					ed[a[res].se].erase({a[res].fi,res});
					un[a[res].se].insert({a[res].fi,res});
					is[x]=1;
					un[a[x].se].erase({a[x].fi,x});
					ed[a[x].se].insert({a[x].fi,x});
					for(int t=a[res].se;t!=a[x].se;t=e[pre[t]^1].b){
						e[pre[t]].c--,e[pre[t^1]].c++;
					}
				}
			}
		}
		printf("%lld\n",ans);
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3840kb

input:

5
BS 3
D 3
B 2
D 4
D 5
2
5 2
1 5

output:

10
12

result:

ok 2 number(s): "10 12"

Test #2:

score: 0
Accepted
time: 146ms
memory: 13176kb

input:

100000
B 727564174
S 231637747
D 246625257
S 975124756
D 844292741
S 809641006
B 396062588
B 883224128
B 311130283
S 434433581
S 509817048
S 993501344
S 508399542
B 279564062
D 950946642
D 819528264
D 412285620
B 968540732
S 953428318
D 902181790
S 172330493
D 725075
B 135580649
D 714478555
B 466916...

output:

40721766963064
40720937650054
40721120372880
40720722768213
40721029809776
40720546822562
40719680807733
40720084910620
40720153432078
40720873952927
40721146683113
40721696875436
40722235723316
40722133896063
40723047443192
40723419347010
40722633976087
40722282806304
40722071958869
40721278798949
...

result:

ok 100000 numbers

Test #3:

score: 0
Accepted
time: 149ms
memory: 13436kb

input:

100000
S 139759881
S 606246897
D 295439937
S 30506154
B 815842927
D 195502949
S 172358189
B 763560428
S 862087943
B 413481091
B 775973599
B 336841814
S 116523655
D 670479401
S 405979654
D 246440323
B 764165518
S 20267667
S 327264314
B 44539411
B 353491632
D 5202858
S 842200033
S 337952200
D 6150168
...

output:

40524529913817
40524860528295
40524824503871
40524293726866
40524353142964
40524176391157
40524132308308
40524134826811
40524107274580
40524341365401
40524194084164
40524572093940
40524910630137
40525296284478
40525633925207
40525793456210
40526041232042
40526041232042
40526144290799
40526737278038
...

result:

ok 100000 numbers

Test #4:

score: 0
Accepted
time: 154ms
memory: 13508kb

input:

100000
B 567185557
S 731841946
S 365565517
D 767568967
B 450159068
D 658059427
S 790559143
B 356623472
S 541664149
D 447906802
B 407933323
S 403512209
D 187294244
D 351683584
S 504286757
D 212023807
B 51119045
S 84059041
S 819097063
D 115224344
B 104478594
B 446088838
D 153595287
S 749172175
S 57160...

output:

40639770818547
40639473223932
40639909468709
40639327970968
40639021798510
40639377404325
40638848317225
40638755074708
40638463360482
40638463360482
40638225443217
40638907566106
40638907566106
40638707391259
40638642781389
40638809562003
40637986313647
40637481713492
40636989271046
40636464147095
...

result:

ok 100000 numbers

Test #5:

score: 0
Accepted
time: 156ms
memory: 13432kb

input:

100000
BS 609181774
BS 498815665
BS 729225393
S 366911976
D 192782776
DB 109052372
D 927091614
SD 120687185
D 619604491
DB 405398892
BS 947957264
DB 134896320
S 909342292
DS 374808683
SD 810910022
D 636083341
D 719767505
D 576713707
DB 327091245
SD 128393617
B 464665485
DB 186653465
S 50744850
BS 31...

output:

49922035989330
49921636770968
49921944461352
49922449756073
49922666981649
49922155391929
49922220626762
49922165472452
49922033364853
49922182879778
49922118499498
49921629498341
49921194947559
49921237943096
49920830551816
49920785993225
49921523763744
49920936362665
49920399195989
49920353383077
...

result:

ok 100000 numbers

Test #6:

score: -100
Wrong Answer
time: 159ms
memory: 13200kb

input:

100000
S 46980313
DS 746577279
S 119614887
D 32418943
B 952739459
S 532231646
SD 559263381
DS 631559122
SB 335561329
SD 935559531
DB 548708848
BD 8298741
DS 403723074
DS 559038896
SB 43327419
SD 430897629
B 483781810
B 31916773
B 39977980
S 405078517
D 323989135
SD 584417860
SB 776661769
D 467791168...

output:

42348275359402
42348652439619
42348713198459
42348631107452
42349074844557
42349760441910
42349962186466
42350429498431
42350447771721
42350361082730
42349972717124
42350266522340
42350463555914
42351167696055
42350739802238
42350725554192
42351107085086
42350772822134
42349881535618
42350109052615
...

result:

wrong answer 32011th numbers differ - expected: '42287980098193', found: '42287702242313'