#include <bits/stdc++.h>
#pragma GCC optimize("O3")
// #define int long long
#define ll long long
#define se second
#define fi first
#define pb push_back
#define lf (id<<1)
#define rg ((id<<1)|1)
#define md ((l+r)>>1)
using namespace std;
typedef pair<int,int> pii;
typedef pair<int,pii> ipii;
const int MAXN = 2e5+10;
const int MAXA = 5e7+10;
const int SQRT = 450;
const int INF = 1e9;
const int MOD = 998244353;
const int LOG = 20;
int sum(int a, int b){ a%=MOD; b%=MOD; return (a+MOD+b)%MOD; }
void chsum(int &a, int b){ a%=MOD; b%=MOD; a = (a+MOD+b)%MOD; }
int mul(int a, int b){ return (a*b)%MOD; }
int expo(int a, int b){
if(b==0) return 1;
int te = expo(a, b/2); te = mul(te,te);
return (b%2 ? mul(te,a) : te);
}
void chmul(int &a, int b){ a = (a*b)%MOD; }
void chmn(auto &a, auto b){ a = min(a, b); }
void chmx(auto &a, auto b){ a = max(a, b); }
int n, m, ans[MAXN];
vector<pii> vec[MAXN];
bool can = 1;
int ban[MAXN];
int le[MAXN], ri[MAXN];
struct seg {
pii st[4*MAXN]; int laz[4*MAXN];
void bd(int id, int l, int r){
if(l==r){
st[id] = {0, l}; return;
}
bd(lf,l,md); bd(rg,md+1,r);
st[id] = min(st[lf], st[rg]);
}
void bnc(int id, int l, int r){
if(laz[id] == 0) return;
st[lf].fi += laz[id]; laz[lf] += laz[id];
st[rg].fi += laz[id]; laz[rg] += laz[id];
laz[id] = 0;
}
pii que(int id, int l, int r, int x, int y){
if(x<=l && r<=y) return st[id];
if(r<x || y<l) return pii(INF, INF);
bnc(id,l,r);
return min(que(lf,l,md,x,y), que(rg,md+1,r,x,y));
}
pii upd(int id, int l, int r, int x, int y, int p){
if(x<=l && r<=y){
laz[id] += p; st[id].fi += p; return st[id];
}
if(r<x || y<l) return st[id];
bnc(id,l,r);
return st[id] = min(upd(lf,l,md,x,y,p), upd(rg,md+1,r,x,y,p));
}
} A;
signed main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin>>n>>m;
for(int i=1; i<=m; i++){
int x, y, p; cin>>x>>y>>p; x++; y++; p++;
vec[p].pb({x,y});
}
vec[1].pb({1,n});
for(int i=n; i>=1; i--){
if(vec[i].empty()) continue;
sort(vec[i].begin(), vec[i].end());
int mn = INF, mx = -1;
for(auto [l, r] : vec[i]) chmn(mn, r), chmx(mx, r);
if(mn < vec[i].back().fi) can = 0;
bool ada = 0;
// cout << i << " i\n";
// cout << vec[i].back().fi << ' ' << mn << " mn\n";
for(int j=vec[i].back().fi; j<=mn; j++){
if(ban[j] == 0){
ans[j] = i, ada = 1; break;
}
}
// for(int j=1; j<=n; j++) cout << ans[j] << " \n"[j==n];
// cout << " pp\n";
if(!ada) can = 0;
// le - ri gk boleh dipake
le[i] = vec[i][0].fi; ri[i] = mx;
for(int j=le[i]; j<=ri[i]; j++) ban[j]++;
}
A.bd(1,1,n);
for(int i=1; i<=n; i++){
if(ans[i]==0) A.upd(1,1,n,i,i,ban[i]);
else A.upd(1,1,n,i,i,INF);
}
for(int i=1; i<=n; i++){
if(!vec[i].empty()){
A.upd(1,1,n,le[i],ri[i], -1);
// for(int j=le[i]; j<=ri[i]; j++) ban[j]--;
continue;
}
pii ret = A.que(1,1,n,1,n);
if(ret.fi != 0) can = 0;
else {
ans[ret.se] = i; A.upd(1,1,n,ret.se,ret.se,INF);
}
}
for(int i=1; i<=n; i++)
if(ans[i]==0) can = 0;
if(!can){
for(int i=1; i<=n; i++) cout << "-1 ";
cout << '\n'; exit(0);
}
for(int i=1; i<=n; i++) cout << ans[i]-1 << " \n"[i==n];
}
컴파일 시 표준 에러 (stderr) 메시지
rmq.cpp:29:11: warning: use of 'auto' in parameter declaration only available with '-std=c++20' or '-fconcepts'
29 | void chmn(auto &a, auto b){ a = min(a, b); }
| ^~~~
rmq.cpp:29:20: warning: use of 'auto' in parameter declaration only available with '-std=c++20' or '-fconcepts'
29 | void chmn(auto &a, auto b){ a = min(a, b); }
| ^~~~
rmq.cpp:30:11: warning: use of 'auto' in parameter declaration only available with '-std=c++20' or '-fconcepts'
30 | void chmx(auto &a, auto b){ a = max(a, b); }
| ^~~~
rmq.cpp:30:20: warning: use of 'auto' in parameter declaration only available with '-std=c++20' or '-fconcepts'
30 | void chmx(auto &a, auto b){ a = max(a, b); }
| ^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |