# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1092627 | ByeWorld | RMQ (NOI17_rmq) | C++14 | 2 ms | 2652 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#define int long long
#define ll long long
#define pb push_back
#define fi first
#define se second
#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 = 1e5+15;
const int INF = 1e18+10;
const int MOD = 998244353;
const int LOG = 32;
int n, m;
vector <ipii> vec;
vector <int> add[MAXN];
int ret[MAXN], ri[MAXN], done[MAXN];
multiset <int> s;
void print(){
return;
cout << "ret\n";
for(int p=1; p<=n; p++) cout << ret[p] << " \n"[p==n];
}
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 l, r, mn; cin>>l>>r>>mn; l++; r++; mn++;
vec.pb({mn, {l, r}});
}
sort(vec.begin(), vec.end());
for(int i=0; i<vec.size(); i++){
int id = i;
int mn = vec[i].se.se, mx = vec[i].se.fi;
while(i+1<vec.size() && vec[i+1].fi==vec[id].fi){
i++;
mn = min(mn, vec[i].se.se);
mx = max(mx, vec[i].se.fi);
}
if(mx <= mn){
add[mx].pb(vec[id].fi);
add[mn+1].pb(-vec[id].fi);
} else {
for(int j=1; j<=n; j++) cout << "-1 ";
cout << '\n';
exit(0);
}
}
for(int i=1; i<=n; i++){
for(auto in : add[i]){
if(in < 0) s.erase(s.find(-in));
else s.insert(in);
}
if(!s.empty()){
ret[i] = *(--s.end());
ri[*(--s.end())] = i;
done[*(--s.end())] = 1;
}
}
print();
for(int i=1; i<=n; i++){
if(done[i]) continue;
// cout << i << " i\n";
for(int j=1; j<=n; j++){
if(ret[j] == 0){
ret[j] = i; ri[i] = j;
break;
}
int bef = ret[j];
// cout << i << ' '<< j << " j\n";
// cout << ret[j] << ' ' << ri[bef] << " pp\n";
if(j == ri[bef]) continue;
ret[j] = i; ri[i] = j;
break;
}
print();
}
bool done = 1;
for(int i=1; i<=n; i++)
if(ret[i] == 0) done = 0;
for(auto [val, ra] : vec){
int l = ra.fi, r = ra.se;
int mn = ret[l];
for(int i=l+1; i<=r; i++) mn = min(mn, ret[i]);
if(mn != val) done = 0;
}
if(!done){
for(int i=1; i<=n; i++) cout << "-1 ";
cout << '\n';
exit(0);
} else {
for(int i=1; i<=n; i++) cout << ret[i]-1 << " \n"[i==n];
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |