QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#117461#4424. Babushka and her pierogiKING_OF_TURTLEAC ✓400ms21744kbC++141.1kb2023-07-01 11:29:432023-07-01 11:31:04

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-01 11:31:04]
  • 评测
  • 测评结果:AC
  • 用时:400ms
  • 内存:21744kb
  • [2023-07-01 11:29:43]
  • 提交

answer

#include<bits/stdc++.h>
#define pii pair<int,int>
#define mp make_pair 
using namespace std;
const int N=1000005;
typedef long long ll;
struct node{
	int x,y,id;
	node(int _x=0,int _y=0,int _id=0):x(_x),y(_y),id(_id){}
	bool operator<(const node &rhs)const{
		return y<rhs.y;
	}
}a[N];
vector<pii> ans;
int T,n,C,p[N],pos[N];ll res;
void upd(int x,int y)
{
	ans.push_back(mp(a[x].id,a[y].id));
	swap(p[x],p[y]);pos[p[x]]=x;pos[p[y]]=y;
	res+=abs(a[x].x-a[y].x)+C;swap(a[x].x,a[y].x);
}
int main()
{
	scanf("%d",&T);
	while(T--)	
	{
		scanf("%d%d",&n,&C);ans.clear();res=0;
		for(int i=1;i<=n;++i)scanf("%d%d",&a[i].x,&a[i].y),a[i].id=i;
		sort(a+1,a+n+1);for(int i=1;i<=n;++i)p[i]=lower_bound(a+1,a+n+1,node(0,a[i].x,0))-a,pos[p[i]]=i;
		for(int i=1;i<=n;++i)
		{
			while(p[i]!=i)
			{
				int l=i,r=i;
				while(1)
				{
					l=p[l];if(l>=p[i]&&p[i]>p[l]){upd(l,i);break;}
					r=pos[r];if(r>=p[i]&&p[i]>p[r]){upd(r,i);break;}
				}
			}
		}
		printf("%lld %d\n",res,(int)ans.size());
		for(auto p:ans)printf("%d %d\n",p.first,p.second);
	}
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 367ms
memory: 20144kb

input:

1000
3220 272696332
766498233 728308608
664527309 611122504
769309894 72297979
848647465 356897274
645591201 895123264
165094010 486891491
31233252 552012226
84149600 93558181
569880970 31233252
925517631 900673333
254671525 65782954
360356809 123019566
435505772 128102614
595657911 878072081
138392...

output:

1425165727822 3210
2743 866
2835 866
1533 3026
907 3026
854 3026
733 3026
1361 2507
1624 2801
164 2801
1819 567
1367 567
1389 2189
1814 2189
451 881
37 881
2412 2329
1319 2329
2760 2329
1110 2243
843 2243
355 1225
1177 1225
3077 1225
621 1225
2382 1225
732 2605
1290 2605
1446 2605
1427 2605
716 3073...

result:

ok ac (1000 test cases)

Test #2:

score: 0
Accepted
time: 400ms
memory: 20612kb

input:

5
200000 42944121
574814309 67495230
53276728 150326725
864637686 234510550
10036337 414740
506850796 483988482
236014120 843625769
809762843 19603788
507104953 885632626
866590783 119176179
188251555 598788216
652874956 535446529
193164017 235823046
925533029 523948529
50446166 36338992
380571133 6...

output:

43086875784557 199984
177024 176783
167123 176783
151066 29816
59325 149462
168834 149462
19518 47437
121747 47437
164375 77177
82430 77177
32697 77177
71557 77177
129942 77177
54145 55856
193283 491
45134 491
27057 491
46967 491
142843 9721
141633 54648
51638 195822
121873 195822
172619 93825
3986 ...

result:

ok ac (5 test cases)

Test #3:

score: 0
Accepted
time: 315ms
memory: 21744kb

input:

5
200000 22877235
36648700 36642254
935593015 935591420
912067011 912055984
229315170 229314259
83126790 83123673
949986358 949980907
563637725 563627158
131644066 131631233
202694678 202691574
747915499 747915206
433149695 433125141
466955691 466945175
770435427 770425839
333350582 333349002
794680...

output:

4576424117766 199999
13670 155223
13670 169318
13670 122272
13670 186701
13670 25846
13670 179211
13670 193487
13670 101581
13670 66607
13670 103962
13670 172890
13670 163342
13670 74383
13670 19151
13670 117913
13670 6901
13670 126267
13670 43459
13670 87097
13670 15151
13670 59717
13670 194422
136...

result:

ok ac (5 test cases)

Extra Test:

score: 0
Extra Test Passed