Submission #425451

#TimeUsernameProblemLanguageResultExecution timeMemory
425451errorgornRMQ (NOI17_rmq)C++17
100 / 100
668 ms32528 KiB
//雪花飄飄北風嘯嘯 //天地一片蒼茫 #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <ext/rope> using namespace std; using namespace __gnu_pbds; using namespace __gnu_cxx; #define ll long long #define ii pair<ll,ll> #define iii pair<ii,ll> #define fi first #define se second #define endl '\n' #define debug(x) cout << #x << " is " << x << endl; #define rep(x,start,end) for(auto x=(start)-((start)>(end));x!=(end)-((start)>(end));((start)<(end)?x++:x--)) #define all(x) (x).begin(),(x).end() #define sz(x) (int)(x).size() ll MAX(ll a){return a;} ll MIN(ll a){return a;} template<typename... Args> ll MAX(ll a,Args... args){return max(a,MAX(args...));} template<typename... Args> ll MIN(ll a,Args... args){return min(a,MIN(args...));} #define indexed_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> mt19937 rng(chrono::system_clock::now().time_since_epoch().count()); struct Q{ ll l,r,val; Q(int a,int b,int c){ l=a,r=b,val=c; } }; struct node{ int s,e,m; ii val; ll lazy=0; node *l,*r; node (int _s,int _e){ s=_s,e=_e,m=s+e>>1; val=ii(0,s); if (s!=e){ l=new node(s,m); r=new node(m+1,e); } } void propo(){ if (lazy){ val.fi+=lazy; if (s!=e){ l->lazy+=lazy; r->lazy+=lazy; } lazy=0; } } void update(int i,int j,ll k){ if (s==i && e==j) lazy+=k; else{ if (j<=m) l->update(i,j,k); else if (m<i) r->update(i,j,k); else l->update(i,m,k),r->update(m+1,j,k); l->propo(),r->propo(); val=min(l->val,r->val); } } ii query(int i,int j){ propo(); if (s==i && e==j) return val; else if (j<=m) return l->query(i,j); else if (m<i) return r->query(i,j); else return min(l->query(i,m),r->query(m+1,j)); } } *root=new node(0,100005); struct node2{ int s,e,m; int mx=-1; node2 *l,*r; node2 (int _s,int _e){ s=_s,e=_e,m=s+e>>1; if (s!=e){ l=new node2(s,m); r=new node2(m+1,e); } } void update(int i,int j,int k){ if (s==i && e==j) mx=max(mx,k); else if (j<=m) l->update(i,j,k); else if (m<i) r->update(i,j,k); else l->update(i,m,k),r->update(m+1,j,k); } int query(int i){ if (s==e) return mx; else if (i<=m) return max(mx,l->query(i)); else return max(mx,r->query(i)); } } *root2=new node2(0,100005); int n,q; ii range[100005]; int cnt[100005]; int ans[100005]; void rage(){ rep(x,0,n) cout<<"-1 "; exit(0); } int main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); memset(ans,-1,sizeof(ans)); cin>>n>>q; rep(x,0,n) range[x]=ii(-1,100005); vector<Q> qu; ll a,b,c; while (q--){ cin>>a>>b>>c; qu.push_back(Q(a,b,c)); root->update(a,b,1); root2->update(a,b,c); range[c].fi=max(range[c].fi,a); range[c].se=min(range[c].se,b); cnt[c]++; } sort(all(qu),[](Q i,Q j){ return i.val>j.val; }); while (!qu.empty()){ int lo=qu.back().val; if (range[lo].fi>range[lo].se) rage(); ii temp=root->query(range[lo].fi,range[lo].se); //cout<<temp.fi<<" "<<temp.se<<endl; if (temp.fi!=cnt[lo]) rage(); int pos=temp.se; ans[pos]=lo; while (!qu.empty() && qu.back().val==lo){ root->update(qu.back().l,qu.back().r,-1); qu.pop_back(); } } vector<int> proc; set<int> avail; rep(x,0,n) avail.insert(x); rep(x,0,n){ if (ans[x]==-1) proc.push_back(x); else avail.erase(ans[x]); } sort(all(proc),[](int i,int j){ return root2->query(i)<root2->query(j); }); for (auto &it:proc){ if (*avail.begin()<root2->query(it)) rage(); ans[it]=*avail.begin(); avail.erase(*avail.begin()); } rep(x,0,n) cout<<ans[x]<<" "; }

Compilation message (stderr)

rmq.cpp: In constructor 'node::node(int, int)':
rmq.cpp:49:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   49 |   s=_s,e=_e,m=s+e>>1;
      |               ~^~
rmq.cpp: In constructor 'node2::node2(int, int)':
rmq.cpp:97:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   97 |   s=_s,e=_e,m=s+e>>1;
      |               ~^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...