Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <math.h>
- #include <stdio.h>
- #include <utility>
- #include <stdlib.h>
- #include <iostream>
- #include <algorithm>
- #define For(i,a,b) for((i)=(a);(i)<=(b);(i)++)
- #define Fod(i,a,b) for((i)=(a);(i)>=(b);(i)--)
- #define sz(x) int((x).size())
- #define NON -(1ll<<35)
- #define mp make_pair
- using namespace std;
- pair<pair<int,int>,int> q[100005];
- bool F[280005];
- long long t[280005],a[100005],Mn;
- int l,r,x,n,m,i,j,tsz;
- int lev,prav,zam;
- void push(int v,int L,int R)
- {
- if(F[v])
- {
- if(L<R)
- {
- F[v*2]=F[v*2+1]=1;
- t[v*2]=t[v*2+1]=t[v];
- }
- F[v]=0;
- }
- }
- void upd(int v,int L,int R)
- {
- push(v,L,R);
- if(R<l || L>r) return;
- if(l<=L && R<=r)
- {
- if(x<t[v])
- {
- puts("inconsistent");
- exit(0);
- }
- F[v]=1; t[v]=x;
- push(v,L,R);
- return;
- }
- upd(v*2,L,(L+R)/2); upd(v*2+1,(L+R)/2+1,R);
- if(t[v*2]==NON) t[v]=t[v*2+1];
- else if(t[v*2+1]==NON) t[v]=t[v*2];
- else t[v]=min(t[v*2],t[v*2+1]);
- }
- void Min(int v,int L,int R)
- {
- push(v,L,R);
- if(R<l || L>r) return;
- if(l<=L && R<=r)
- {
- Mn=min(Mn,t[v]);
- return;
- }
- Min(v*2,L,(L+R)/2); Min(v*2+1,(L+R)/2+1,R);
- if(t[v*2]==NON) t[v]=t[v*2+1];
- else if(t[v*2+1]==NON) t[v]=t[v*2];
- else t[v]=min(t[v*2],t[v*2+1]);
- }
- void out(int v,int L,int R)
- {
- if(t[v]==NON) return;
- if(F[v] || L==R)
- {
- For(i,L,R) a[i]=t[v];
- return;
- }
- out(v*2,L,(L+R)/2); out(v*2+1,(L+R)/2+1,R);
- }
- #define Left first.first
- #define Right first.second
- #define Num second
- bool cmp(pair<pair<int,int>,int> X,pair<pair<int,int>,int> Y)
- {
- return (X.Num<Y.Num);
- }
- int main()
- {
- freopen("rmq.in","r",stdin);
- freopen("rmq.out","w",stdout);
- scanf("%d%d",&n,&m);
- for(tsz=1;tsz<n;tsz*=2);
- For(i,1,tsz*2-1) t[i]=NON;
- For(i,1,m)
- {
- scanf("%d%d%d",&lev,&prav,&zam);
- q[i]=mp(mp(lev,prav),zam);
- }
- sort(q+1,q+m+1,cmp);
- For(i,1,m)
- {
- l=q[i].Left; r=q[i].Right; x=q[i].Num;
- upd(1,1,tsz);
- }
- out(1,1,tsz);
- For(i,1,m)
- {
- l=q[i].Left; r=q[i].Right; x=q[i].Num;
- Mn=(1ll<<35); Min(1,1,tsz);
- if(x!=Mn) {
- printf("inconsistent");
- return 0;
- }
- }
- puts("consistent");
- For(i,1,n) printf("%I64d ",a[i]);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement