QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#56054 | #4883. Bayan Testing | triple__a# | WA | 69ms | 38816kb | C++ | 2.3kb | 2022-10-16 18:16:48 | 2022-10-16 18:16:49 |
Judging History
answer
// #pragma comment(linker, "/STACK:102400000,102400000")
#pragma GCC optimize("O3")
#pragma GCC optimize("O2")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
// #pragma GCC optimize("trapv")
#include<bits/stdc++.h>
// #include <bits/extc++.h>
#define int long long
#define double long double
// #define i128 long long
// #define double long double
using namespace std;
#define rep(i,n) for (int i=0;i<(int)(n);++i)
#define rep1(i,n) for (int i=1;i<=(int)(n);++i)
#define range(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define pb push_back
#define F first
#define S second
typedef long long ll;
typedef unsigned long long ull;
// typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
int dx[]={1,-1,0,0};
int dy[]={0,0,1,-1};
// const int mod[]={998244353,(int)1e9+7};
const int mod=998244353;
const int base[]={12321,32123};
const double EPS=8e-6;
// const double pi=acos(-1);
const int INF=1e12;
const int N=1500007;
mt19937 rng(1235);
const int B=500;
int l[N], r[N],p[N];
int ans[N];
vi lst[N];
signed main(){
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
cout.precision(15);
int _;
cin>>_;
while (_--){
int n,m;
cin>>n>>m;
rep(i,2*m) cin>>l[i]>>r[i], l[i]--;
int sum=0;
rep(i,2*m) {
if (r[i]==l[i]+1) sum++;
}
if (sum>m){
cout<<"-1\n";
continue;
}
rep(i,2*m) p[i]=i;
sort(p,p+2*m,[&](int u,int v){return (r[u]-l[u]<r[v]-l[v])||(r[u]-l[u]==r[v]-l[v]&&l[u]<l[v]);});
rep(i,n+2) lst[i].clear();
rep(i,m) lst[l[p[i]]].pb(1);
rep(i,m) lst[r[p[i]]].pb(~l[p[i]]);
map<int,int> nw;
set<int> rem;
for (int i=0;i<n+3;++i) rem.insert(i);
int L=0;
for (int i=0;i<n;++i){
for (auto c:lst[i]){
if (c>0) nw[i]++;
else {
nw[~c]--;
if (!nw[~c]) nw.erase(~c);
}
}
int ret;
if (!sz(nw)) ret=i;
else ret=nw.begin()->F;
for (;L<ret;L++) rem.insert(ans[L]);
ans[i]=*rem.begin();
rem.erase(ans[i]);
}
rep(i,n) cout<<ans[i]+2<<" ";
cout<<"\n";
}
return 0;
}
/*
3
2 1
1 1
2 2
6 2
1 3
4 6
2 4
3 5
4 3
1 2
1 1
2 2
2 3
3 3
3 4
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 12ms
memory: 38816kb
input:
3 2 1 1 1 2 2 6 2 1 3 4 6 2 4 3 5 4 3 1 2 1 1 2 2 2 3 3 3 3 4
output:
-1 2 3 4 2 2 2 2 2 2 2
result:
ok ok (3 test cases)
Test #2:
score: 0
Accepted
time: 65ms
memory: 38736kb
input:
100000 2 1 1 1 2 2 2 1 2 2 1 2 2 1 1 2 2 2 2 1 1 2 2 2 2 1 2 2 1 2 2 1 2 2 1 1 2 1 1 1 2 2 2 1 1 2 2 2 2 1 2 2 1 1 2 1 2 2 1 2 2 1 2 2 1 1 2 1 2 2 1 2 2 1 2 2 1 2 2 1 2 2 1 1 2 1 2 2 1 1 2 1 1 2 2 2 2 1 2 2 1 2 2 1 2 2 1 2 2 1 2 2 1 2 2 1 1 1 2 2 2 1 2 2 1 2 2 1 1 1 2 2 2 1 1 1 2 2 2 1 2 2 1 2 2 1 2...
output:
-1 2 2 2 2 2 2 2 2 -1 -1 2 2 -1 2 2 -1 2 2 2 2 -1 -1 2 2 2 2 2 2 2 2 -1 2 2 -1 -1 2 2 -1 2 2 2 2 -1 -1 2 2 2 2 -1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 -1 2 2 2 2 2 2 2 2 2 2 2 2 -1 2 2 2 2 2 2 2 2 -1 2 2 -1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 -1 2 2 2 2 2 2 -1 -1 2 ...
result:
ok ok (100000 test cases)
Test #3:
score: -100
Wrong Answer
time: 69ms
memory: 38756kb
input:
25000 10 5 4 10 1 4 9 9 2 9 5 8 1 8 1 5 5 5 4 9 6 6 11 5 9 11 4 7 2 2 2 5 8 10 3 11 2 4 4 8 3 10 4 6 5 2 1 3 4 4 1 5 5 5 6 3 4 6 3 3 1 5 3 6 1 1 1 3 7 3 4 4 3 5 1 6 3 4 2 3 1 2 7 3 3 4 1 5 6 7 2 6 3 5 2 3 5 2 5 5 4 5 2 3 1 1 10 5 3 6 4 5 3 3 6 9 2 5 9 10 5 6 5 7 1 4 8 9 11 5 1 10 2 11 6 9 2 6 6 6 8 ...
output:
2 3 4 5 2 3 4 5 2 2 2 2 3 4 2 3 2 2 3 4 2 2 2 2 2 2 2 3 4 2 2 2 2 3 2 2 2 2 2 2 2 3 2 2 2 3 2 2 2 2 2 2 2 2 2 3 2 2 2 3 2 2 2 3 4 5 2 3 4 5 2 3 2 3 4 2 2 2 3 2 2 3 4 5 6 2 3 2 2 3 2 3 2 4 5 2 3 2 2 3 2 3 4 2 2 2 3 2 2 2 3 2 2 2 2 2 2 2 2 3 4 2 3 4 5 2 3 2 2 3 2 2 2 2 2 2 3 4 2 2 3 2 4...
result:
wrong answer the number of segments with two equal elements is 4 != 5 (test case 9)