QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#235334 | #2832. Graph Theory | yiyiyi# | TL | 105ms | 9832kb | C++14 | 1.3kb | 2023-11-02 17:24:30 | 2023-11-02 17:24:30 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
#define inf 0x3f3f3f3f
#define re register
#define N 202000
#define pii pair<int,int>
#define fi first
#define se second
#define ll long long
using namespace std;
const int mo=998244353;
inline int read(){
int x=0,w=0;char ch=getchar();
while (!isdigit(ch))w|=ch=='-',ch=getchar();
while (isdigit(ch))x=(x<<1)+(x<<3)+ch-'0',ch=getchar();
return w?-x:x;
}
int n,m,q,a[N],b[N],gg[N],f[N];
bool ck(int x){
set<int>s;
for (int i=1;i<=n;++i)s.insert(i);
for (int i=1;i<=m;++i){
if (a[i]>b[i])swap(a[i],b[i]);
int mx=max(n-(b[i]-a[i]),b[i]-a[i]),mn=min(n-(b[i]-a[i]),b[i]-a[i]);
if (mn>x)return 0;
if (mx<=x)continue;
if (b[i]-a[i]==mn){
auto x=s.lower_bound(a[i]);
while (x!=s.end()&&*x<b[i]){
auto y=x;++x;
s.erase(y);
}
}else{
while (s.size()&&*s.begin()<a[i])s.erase(s.begin());
while (s.size()&&*--s.end()>=b[i])s.erase(--s.end());
}
}
return s.size();
}
void solve(){
while (scanf("%lld%lld",&n,&m)!=EOF){
for (int i=1;i<=m;++i)a[i]=read(),b[i]=read();
int l=0,r=n,res=0;
while (l<=r){
int mid=(l+r)>>1;
if (ck(mid))r=mid-1,res=mid;
else l=mid+1;
}
printf("%lld\n",res);
}
}
signed main(){
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 5840kb
input:
3 2 1 2 2 3 3 2 1 1 2 2 3 3 1 2 2 3 3 1
output:
1 0 2
result:
ok 3 lines
Test #2:
score: 0
Accepted
time: 1ms
memory: 8208kb
input:
2 1 1 2
output:
1
result:
ok single line: '1'
Test #3:
score: 0
Accepted
time: 28ms
memory: 5868kb
input:
17 17 6 10 1 9 14 6 12 13 5 4 15 17 14 15 6 5 10 6 10 11 2 9 9 6 17 15 9 15 4 8 1 4 13 15 13 19 11 10 12 10 10 5 2 8 12 11 8 3 1 7 10 9 8 5 1 5 9 4 8 7 12 10 6 8 13 1 5 8 11 5 10 8 7 7 16 14 9 5 8 1 4 16 10 8 16 15 15 1 13 5 9 3 4 4 9 7 7 2 5 4 5 11 9 14 5 13 1 5 4 5 4 1 4 4 1 1 5 3 3 5 4 1 3 2 5 1 ...
output:
8 6 8 2 1 2 7 6 2 6 2 9 10 10 8 10 3 8 7 7 9 10 4 8 6 8 2 2 2 6 6 5 5 4 2 9 4 1 9 6 9 2 6 4 1 2 1 3 6 8 8 6 3 4 7 6 3 8 1 5 3 2 1 5 8 5 7 5 6 7 10 9 3 2 6 7 4 5 6 6 5 1 4 2 4 1 9 7 3 9 4 6 7 5 7 6 1 5 8 5 6 4 5 3 3 7 7 6 9 2 7 3 3 7 10 7 1 2 2 6 6 7 8 7 2 5 1 3 7 2 1 9 9 5 9 5 2 3 1 6 6 3 8 6 1 8 3 ...
result:
ok 10000 lines
Test #4:
score: 0
Accepted
time: 36ms
memory: 5884kb
input:
190 27 72 104 45 123 187 67 105 21 52 179 141 79 107 23 111 166 27 186 35 15 1 59 48 67 105 153 51 92 92 178 149 98 86 153 144 100 13 100 186 91 124 153 24 116 75 15 105 18 137 52 150 129 109 100 106 100 15 36 52 105 7 19 40 62 19 95 26 90 67 55 14 104 90 45 59 41 78 61 100 96 77 55 75 85 13 76 50 1...
output:
95 53 25 77 43 78 94 14 83 35 24 70 46 17 12 38 6 19 21 68 45 87 40 28 38 52 11 10 11 26 48 80 92 48 94 56 12 22 19 1 45 60 9 59 82 44 12 85 24 34 25 90 71 60 43 16 74 9 36 83 19 54 37 76 82 53 21 30 18 86 15 91 63 45 18 22 13 53 71 49 77 67 25 58 44 67 28 87 44 6 67 12 34 93 12 33 21 67 69 100 96 7...
result:
ok 1000 lines
Test #5:
score: 0
Accepted
time: 65ms
memory: 7960kb
input:
631 403 564 132 336 393 68 11 23 519 24 399 463 382 550 163 557 333 404 578 139 46 576 72 207 424 408 224 509 551 12 389 119 490 239 462 531 363 295 607 87 91 525 469 493 133 22 450 325 557 348 29 594 380 495 540 45 387 452 64 562 585 539 403 516 212 511 153 347 186 59 51 475 453 426 463 363 570 127...
output:
315 105 859 936 348 811 510 237 852 571 482 496 996 192 445 19 840 235 569 915 267 977 587 468 574 461 412 436 89 794 314 656 693 794 640 15 43 885 667 891 559 237 275 268 43 774 197 914 510 817 264 406 813 781 657 410 665 193 523 943 846 427 985 200 592 786 502 804 308 615 395 814 455 585 990 93 27...
result:
ok 100 lines
Test #6:
score: 0
Accepted
time: 105ms
memory: 9832kb
input:
33612 200000 24258 24258 16589 16578 27435 27434 12485 12483 27768 27779 25352 25365 7899 7890 21677 21679 18384 18403 8639 8647 25720 25731 12560 12553 6818 6821 6737 6721 756 738 24289 24278 25287 25299 15980 15968 30378 30385 16423 16439 8410 8430 13605 13623 8786 8779 15942 15943 8070 8086 1114 ...
output:
20
result:
ok single line: '20'
Test #7:
score: -100
Time Limit Exceeded
input:
200000 200000 108194 108177 107888 107907 151974 151986 145582 145564 160644 160655 6520 6512 27546 27560 54120 54109 23774 23761 139151 139169 3715 3704 37270 37261 27979 27961 68030 68029 172350 172337 136551 136539 71687 71702 72681 72683 170998 171009 102032 102015 86070 86050 49785 49795 70532 ...