forked from imabhinav-am/Competetive-Programming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommands4.cpp
More file actions
69 lines (68 loc) · 912 Bytes
/
Commands4.cpp
File metadata and controls
69 lines (68 loc) · 912 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include<iostream>
#include<vector>
using namespace std;
struct cmd
{
int no;
int lw;
int up;
};
int ctr=0,flag=0;
void calc(vector<int> &A,vector<cmd> &Cmd,int x,int y)
{
if(Cmd[x-1].no==1)
ctr++;
for(int i=x-1;i<y;i++)
{
if(Cmd[i].no==2)
{
flag=1;
calc(A,Cmd,Cmd[i].lw,Cmd[i].up);
}
}
}
int main()
{
int n,N,M;
cin>>n;
while(n>0)
{
cin>>N>>M;
vector<int> A(N,0);
vector<cmd> Cmd;
ctr=0;
flag=0;
for(int i=0;i<M;i++)
{
Cmd.push_back(cmd());
cin>>Cmd[i].no;
cin>>Cmd[i].lw;
cin>>Cmd[i].up;
}
calc(A,Cmd,1,M);
if(flag==0)
{
ctr=0;
for(int i=0;i<M;i++)
{
if(Cmd[i].no==2)
break;
else
ctr++;
}
}
for(int i=0;i<M;i++)
{
if(Cmd[i].no==2)
break;
else
for(int j=Cmd[i].lw-1;j<Cmd[i].up;j++)
if(A.at(j)==0)
A.at(j)=ctr;
}
for(int i=0;i<N;i++)
cout<<A.at(i)<<" ";
cout<<endl;
n--;
}
}