QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#865662 | #9733. Heavy-light Decomposition | Purslane# | WA | 0ms | 3712kb | C++14 | 1.1kb | 2025-01-21 20:55:38 | 2025-01-21 20:55:46 |
Judging History
answer
#include<bits/stdc++.h>
#define ffor(i,a,b) for(int i=(a);i<=(b);i++)
#define roff(i,a,b) for(int i=(a);i>=(b);i--)
using namespace std;
const int MAXN=1e5+10;
int T,n,k,l[MAXN],r[MAXN],fa[MAXN];
int main() {
ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
cin>>T;
while(T--) {
cin>>n>>k;
ffor(i,1,k) cin>>l[i]>>r[i];
vector<pair<int,int>> st;
ffor(i,1,k) st.push_back({r[i]-l[i]+1,l[i]});
sort(st.begin(),st.end());
ffor(i,1,n) fa[i]=0;
if(st.size()==1) {ffor(i,1,n) cout<<i-1<<' ';cout<<'\n';continue ;}
if(st[0].first==st[st.size()-1].first) {cout<<"IMPOSSIBLE\n";continue ;}
int al=0;
ffor(i,0,(int)st.size()-1) {
int l=st[i].second,len=st[i].first;
ffor(j,l+1,l+len-1) fa[j]=j-1;
if(i==st.size()-1) continue ;
if(len!=st[st.size()-1].first) fa[l]=st[st.size()-1].second+st[st.size()-1].first-1-len;
else fa[l]=st[st.size()-1].second;
if(len!=st[st.size()-1].first&&fa[l]!=st[st.size()-1].second) al++;
}
if(al) ffor(i,1,n) cout<<fa[i]<<' ';
else cout<<"IMPOSSIBLE";
cout<<'\n';
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3712kb
input:
3 12 5 1 5 9 11 7 8 6 6 12 12 4 3 1 1 4 4 2 3 2 2 1 1 2 2
output:
0 1 2 3 4 4 3 7 2 9 10 4 IMPOSSIBLE IMPOSSIBLE
result:
wrong answer Case 2, jury find a solution while participant not. (test case 2)