#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#define pb emplace_back
#define rg register
using namespace std;
const int maxn=1e5+10,maxb=pow(maxn,0.5)+10;
int t;
int arr[maxn],l[maxb],r[maxb],belong[maxn],tag[maxn];
//sqrt tech lol hope 20*n*sqrt(1e5) is fast or i had to got seg treesss
inline void mod(int x, int k){
arr[x]=k;
int xx=belong[x];tag[xx]=-1e9;
for(rg int i=l[xx];i<=r[xx];i++) tag[xx]=max(tag[xx],arr[i]);
}
inline int query(int x, int y){
int xx=belong[x],yy=belong[y],cnt=-1e9;
if(xx==yy){
for(rg int i=x;i<=y;i++) cnt=max(cnt,arr[i]);
}else{
for(rg int i=x;i<=r[xx];i++) cnt=max(cnt,arr[i]);
for(rg int i=l[yy];i<=y;i++) cnt=max(cnt,arr[i]);
for(rg int i=xx+1;i<=yy-1;i++){cnt=max(cnt,tag[i]);}
}
return cnt;
}
inline void work(){
vector<int> upp;vector<pair<int,int>> qu;
int n,q,c;cin>>n>>q>>c;
int block=pow(n,0.5),t=n/block;
if(n%block) t++;
for(rg int i=1;i<=t;i++){
l[i]=(i-1)*block+1;
r[i]=i*block;
tag[i]=-1e9;
}r[t]=n;
for(int i=1;i<=n;i++) belong[i]=(i-1)/block+1;
upp.pb(-1),qu.pb(make_pair(-1,-1));
for(int i=1;i<=n;i++){int a;cin>>a;mod(i,a);upp.pb(a);}
for(rg int i=1;i<=n;i++){tag[belong[i]]=max(tag[belong[i]],arr[i]);}
for(int i=1;i<=q;i++){
int a,b;cin>>a>>b;
qu.pb(make_pair(a,b));
}
sort(qu.begin(),qu.end());
if(arr[1]==0) mod(1,1);
for(auto i:qu){
if(i.first==-1) continue;
int l=i.first,r=i.second;
int ll=query(1,l),rr=query(1,r-1),now=query(1,r);
if(ll==now){
if(arr[r]){ //nah! already taken up
cout<<-1<<"\n";
return;
}
mod(r,ll+1);
}
if(ll<rr){
bool flag=0;
for(int j=l;j>=1;j--){
if(!upp[j]){
mod(j,rr);//find a place to put in
flag=1;
break;
}
}
if(!flag){cout<<-1<<endl;return;} //no pos->no solution
}
}
int maxi=-1e9;
for(rg int i=1;i<=n;i++){
if(arr[i]==0) mod(i,1);
maxi=max(maxi,arr[i]);
}
if(maxi>c){cout<<-1<<"\n";return;}
for(auto i:qu){
if(i.first==-1) continue;
int l=i.first,r=i.second;
int ll=query(1,l),rr=query(1,r-1),now=query(1,r);
if(ll==now or ll<rr){
cout<<-1<<"\n";
return;
}
}
for(rg int i=1;i<=n;i++) cout<<arr[i]<<(i!=n?" ":"");
cout<<"\n";
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(NULL),cout.tie(NULL);
cin>>t;
while(t--){
work();
}
return 0;
}
/*8 4 9
0 0 0 0 1 6 0 6
1 3
6 7
4 7
2 3*/剪贴板
剪贴板 gyy95rmx
剪贴板信息
剪贴板信息
- 收录
- 更新