QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#607941 | #1173. Knowledge Is... | Hollow_knight_ | WA | 2ms | 14044kb | C++14 | 1.5kb | 2024-10-03 17:13:41 | 2024-10-03 17:13:41 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=5e5+15;
inline ll read(){
ll x=0;char f=1,c=getchar();
while(c<48||c>57){if(c=='-')f=0;c=getchar();}
while(c>=48&&c<=57){x=(x<<1)+(x<<3)+ll(c)-48;c=getchar();}
return f==1?x:-x;
}
int n,m,p[N],l[N],r[N],vl[N],vr[N],ans[N];
inline bool cmpl(int x,int y){return l[x]>l[y];}
inline bool cmpr(int x,int y){return r[x]<r[y];}
inline bool check(int x){
for(int i=1,j=x;i<=x;++i,--j){
if(r[vr[i]]>=l[vl[j]])return false;
}
return true;
}
inline void mk(int x){
fill(ans+1,ans+n+1,0);
for(int i=1,j=x;i<=x;++i,--j){
ans[vr[i]]=i,ans[vl[j]]=i;
}
int cnt=x+1;
for(int i=1;i<=n&&cnt<=m;++i){
if(!ans[i])ans[i]=cnt++;
}
}
int solve(){
n=read(),m=read();
for(int i=1;i<=n;++i){
l[i]=read(),r[i]=read();
}
for(int i=1;i<=n;++i)p[i]=i;
sort(p+1,p+n+1,cmpr);
for(int i=1;i<=n;++i)vr[i]=p[i];
sort(p+1,p+n+1,cmpl);
for(int i=1;i<=n;++i)vl[i]=p[i];
int l=0,r=m,mid=0,mx=0;
while(l<=r){
mid=((l+r)>>1);
if(check(mid))mx=mid,l=mid+1,mk(mid);
else r=mid-1;
}
for(int i=1;i<=n;++i)printf("%d ",ans[i]);
printf("\n");
return 0;
}
/*
5
9 13
3 7
9 12
7 10
3 7
2
10
37 41
78 84
30 37
94 98
52 58
3 9
76 83
58 62
50 56
17 25
5
7
9 10
7 9
3 4
9 10
2 6
8 9
5 8
3
*/
int main(){
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
int T=1;
while(T--){
solve();
}
fclose(stdin),fclose(stdout);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 14032kb
input:
7 5 9 10 7 9 3 4 9 10 2 6 8 9 5 8
output:
3 4 1 2 2 1 3
result:
ok answer = 7
Test #2:
score: 0
Accepted
time: 0ms
memory: 11956kb
input:
2 2 1 2 3 4
output:
1 1
result:
ok answer = 2
Test #3:
score: 0
Accepted
time: 2ms
memory: 14044kb
input:
2 1 1 2 2 3
output:
1 0
result:
ok answer = 1
Test #4:
score: 0
Accepted
time: 0ms
memory: 12004kb
input:
1 1 4 26
output:
1
result:
ok answer = 1
Test #5:
score: 0
Accepted
time: 2ms
memory: 12016kb
input:
500 258 1 3 3 5 2 4 3 5 4 5 4 5 1 4 1 2 3 5 2 5 2 5 4 5 4 5 4 5 2 3 1 4 1 4 1 4 4 5 4 5 2 3 4 5 3 5 3 5 1 5 1 4 2 5 1 5 3 5 3 4 4 5 2 3 3 5 3 5 4 5 2 3 1 5 1 5 2 3 2 3 3 4 3 5 3 4 1 3 1 2 1 5 4 5 2 3 2 4 1 3 4 5 4 5 4 5 1 3 3 5 4 5 3 5 1 5 1 2 1 2 3 5 3 5 4 5 3 4 3 5 2 3 2 5 2 4 2 5 3 5 2 3 1 5 4 5 ...
output:
83 119 120 121 92 91 122 27 123 124 125 99 89 84 93 126 127 128 88 87 96 86 129 130 131 132 133 134 135 136 85 91 137 138 17 77 139 140 85 84 141 142 143 89 15 144 98 80 145 79 97 96 93 115 146 95 147 148 1 7 149 150 94 151 152 110 153 154 155 156 106 157 115 158 159 102 114 160 161 54 113 162 28 33...
result:
ok answer = 376
Test #6:
score: -100
Wrong Answer
time: 2ms
memory: 12088kb
input:
500 242 8 9 9 10 2 9 8 10 9 10 6 10 4 8 4 5 2 6 7 10 3 8 1 8 1 6 5 9 7 8 8 10 8 9 8 10 2 9 2 3 6 8 3 10 5 9 1 3 6 8 4 10 9 10 8 9 8 10 1 9 3 9 3 7 2 3 6 10 3 6 6 10 3 4 3 6 9 10 5 7 8 10 6 10 5 6 5 7 7 8 1 3 4 7 9 10 4 9 2 4 8 9 1 3 8 10 3 4 9 10 4 9 5 10 8 9 1 3 1 5 8 10 3 4 8 9 3 9 3 6 3 10 6 7 7 ...
output:
159 170 230 141 177 22 214 69 77 57 229 227 108 231 172 115 123 106 232 15 195 233 234 12 175 235 183 134 120 236 237 158 7 238 88 5 22 89 211 129 156 41 101 128 168 13 147 197 239 29 144 17 113 31 187 240 241 127 19 68 148 28 132 242 92 0 155 225 0 182 99 104 0 103 146 169 224 223 144 0 222 221 171...
result:
wrong answer participant answer = 442, judge answer = 471