# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1092924 | 2024-09-25T11:29:51 Z | ByeWorld | RMQ (NOI17_rmq) | C++14 | 1 ms | 2652 KB |
#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; int ans[MAXN], done[MAXN], ri[MAXN]; vector <ipii> vec; vector <int> add[MAXN]; multiset <int> s; bool aman = 1; 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}}); add[l].pb(mn); add[r+1].pb(-mn); } 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()){ ans[i] = *(--s.end()); done[ans[i]] = 1; ri[ans[i]] = i; } } sort(vec.begin(), vec.end()); for(int i=0; i<vec.size(); i++){ int id = i, mn = vec[i].se.se, mx = vec[i].se.fi; while(i+1<vec.size() && vec[id].fi==vec[i+1].fi){ i++; mn = min(mn, vec[i].se.se); mx = max(mx, vec[i].se.fi); } if(mx <= mn){ ri[ vec[i].fi ] = mn; } else aman = 0; } // for(int i=1; i<=n; i++) cout << ri[i] << " \n"[i==n]; // cout << "ans\n"; // for(int i=1; i<=n; i++) cout << ans[i] << " \n"[i==n]; for(int i=1; i<=n; i++){ if(done[i]) continue; for(int j=1; j<=n; j++){ if(ans[j] == 0){ ans[j] = i; ri[i] = j; break; } if(ri[ans[j]] == j || ans[j] > i) continue; ans[j] = i; ri[i] = j; break; } // cout << "ans\n"; // for(int p=1; p<=n; p++) cout << ans[p] << " \n"[p==n]; } for(auto [mn, ran] : vec){ int l=ran.fi, r=ran.se; int val = ans[l]; for(int j=l+1; j<=r; j++) val = min(val, ans[j]); if(val != mn) aman = 0; } for(int i=1; i<=n; i++) done[i] = 0; for(int i=1; i<=n; i++) done[ans[i]] = 1; for(int i=1; i<=n; i++) if(!done[i]) aman = 0; if(!aman){ for(int i=1; i<=n; i++) cout << "-1 "; cout << '\n'; } else { for(int i=1; i<=n; i++) cout << ans[i]-1 << ' '; cout << '\n'; } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 2652 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 2652 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 2652 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |