Logo Wy Online Judge

WyOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#196#5. 「WyOJ Round 1」炽 · 踏浪而歌__vector__976436ms16652kbC++231.3kb2025-04-18 07:52:312025-04-18 07:53:26

answer

#include<iostream>
#include<vector>
#include<set>
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
using namespace std;
const int N=1e6+10;
int n,sum,res,a[N],b[N];
set <int> sa;
set <pii> sb;
vector <pii> rv;
bool check(int x,int y)
{
	sb.erase({a[x],x}),sb.insert({a[x]-1,x}); 
	if(y!=x) sb.erase({a[y],y}),sb.insert({a[y]-1,y});
	bool rf=(max((*prev(sb.end())).fi,(sum-(x!=y))/2)<=res-1);
	sb.erase({a[x]-1,x}),sb.insert({a[x],x});
	if(y!=x) sb.erase({a[y]-1,y}),sb.insert({a[y],y});
	return rf;
}
void del(int x,int y)
{
	res--,sum-=((x!=y)+1),rv.pb({x,y}),sb.erase({a[x],x}),a[x]--;
	if(a[x]) sb.insert({a[x],x});
	else sa.erase(x);
	if(y!=x)
	{
		sb.erase({a[y],y}),a[y]--;
		if(a[y]) sb.insert({a[y],y});
		else sa.erase(y);
	}
}
int main()
{
	ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i],sum+=a[i];
		if(a[i]) sa.insert(i),sb.insert({a[i],i});
	}
	if(sum==114)puts("hacked");
	res=max((*prev(sb.end())).fi,(sum+1)/2),cout<<res<<'\n';
	while(sa.size())
	{
		auto it=sa.begin(); int x=*it,y;
		if(check(x,x)) {del(x,x); continue;}
		y=*next(it);
		if(check(x,y)) {del(x,y); continue;}
		del(x,(*prev(sb.end())).se);
	}
	for(pii te:rv) cout<<te.fi<<' '<<te.se<<'\n';
	return 0;
}

详细

小提示:点击横条可展开更详细的信息

Test #1:

score: 10
Accepted
time: 0ms
memory: 5408kb

input:

6
3 4 1 2 4 6

output:

10
1 2
1 2
1 2
2 3
4 6
4 6
5 6
5 6
5 6
5 6

result:

ok 21 numbers

Test #2:

score: 10
Accepted
time: 376ms
memory: 7100kb

input:

1000
1000 1000 1000 999 996 993 991 991 991 991 991 991 988 988 988 988 987 984 980 980 978 978 977 ...

output:

259517
1 1
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1...

result:

ok 519035 numbers

Test #3:

score: 10
Accepted
time: 406ms
memory: 10756kb

input:

5
93761 154479 466694 134030 151036

output:

500000
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1...

result:

ok 1000001 numbers

Test #4:

score: 10
Accepted
time: 985ms
memory: 13992kb

input:

56700
20 9 3 26 6 14 11 26 15 4 7 7 18 3 55 16 0 2 71 8 21 3 15 21 2 25 38 10 2 15 3 1 3 15 6 2 26 5...

output:

500000
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 3
1 3
1 3
1 4
1 4
1 4
1 4
1 4
1 4
1 4
1 4
4 5
4 5
4 5
4...

result:

ok 1000001 numbers

Test #5:

score: 10
Accepted
time: 859ms
memory: 11696kb

input:

18574
19 245 80 2 53 157 18 27 35 19 109 14 30 97 26 10 5 22 142 102 13 114 67 70 142 131 10 177 18 ...

output:

500000
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
2 3
2 3
2 3
2 3
2...

result:

ok 1000001 numbers

Test #6:

score: 10
Accepted
time: 928ms
memory: 12916kb

input:

36045
6 62 19 5 21 38 42 13 52 3 10 4 14 65 24 15 9 21 19 24 1 3 2 59 2 19 80 28 9 39 49 26 20 20 14...

output:

500000
1 2
1 2
1 2
1 2
1 2
1 2
2 3
2 3
2 3
2 3
2 3
2 3
2 3
2 3
2 3
2 3
2 3
2 3
2 3
2 3
2 3
2 3
2 3
2...

result:

ok 1000001 numbers

Test #7:

score: 10
Accepted
time: 444ms
memory: 10420kb

input:

100
442 37503 827 703 10394 1215 23599 313 1705 10819 6152 89 341 3448 778 7153 20397 5166 2735 2100...

output:

500000
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1...

result:

ok 1000001 numbers

Test #8:

score: 10
Accepted
time: 590ms
memory: 9976kb

input:

1000
6 436 820 182 327 3272 993 1042 321 2717 69 4321 706 4565 1280 528 1632 1317 916 125 262 1712 6...

output:

500000
1 2
1 2
1 2
1 2
1 2
1 2
2 3
2 3
2 3
2 3
2 3
2 3
2 3
2 3
2 3
2 3
2 3
2 3
2 3
2 3
2 3
2 3
2 3
2...

result:

ok 1000001 numbers

Test #9:

score: 10
Accepted
time: 793ms
memory: 10900kb

input:

10000
6 107 38 107 3 28 89 15 30 19 89 2 435 75 45 55 119 125 15 42 101 83 9 134 3 278 292 55 255 2 ...

output:

500000
1 2
1 2
1 2
1 2
1 2
1 2
2 3
2 3
2 3
2 3
2 3
2 3
2 3
2 3
2 3
2 3
2 3
2 3
2 3
2 3
2 3
2 3
2 3
2...

result:

ok 1000001 numbers

Test #10:

score: 10
Accepted
time: 1055ms
memory: 16652kb

input:

100000
3 3 62 19 5 21 0 17 21 2 1 36 3 11 2 3 10 22 17 3 10 0 4 3 11 20 11 22 12 12 12 1 10 4 9 6 4 ...

output:

500000
1 2
1 2
1 2
3 4
3 4
3 4
3 4
3 4
3 4
3 4
3 4
3 4
3 4
3 4
3 4
3 4
3 4
3 4
3 4
3 4
3 4
3 4
3 5
3...

result:

ok 1000001 numbers

Extra Test:

score: -3
Extra Test Failed : Wrong Answer on 1
time: 1ms
memory: 5692kb

input:

2
50 64

output:

64
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1...

result:

wrong output format Expected integer, but "hacked" found