forked from imabhinav-am/Competetive-Programming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommands5.cpp
More file actions
78 lines (77 loc) · 1.2 KB
/
Copy pathCommands5.cpp
File metadata and controls
78 lines (77 loc) · 1.2 KB
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
69
70
71
72
73
74
75
76
77
#include<iostream>
#include<vector>
using namespace std;
struct cmd
{
int no;
int lw;
int up;
};
struct inc
{
int u;
int l;
int ctr;
};
int X=0,Y;
int chk(vector<inc> &increment,int x,int y)
{
for(int i=0;i<increment.size();i++)
{
if(increment[i].u==x && increment[i].l==y)
return i;
}
return -1;
}
void calc(vector<int> &A,vector<cmd> &Cmd,vector<inc> &increment,int x,int y)
{
for(int i=x-1;i<y;i++)
{
if(Cmd[i].no==1)
{
Y=chk(increment,Cmd[i].up,Cmd[i].lw);
if(Y>=0)
increment[Y].ctr+=1;
else
{
increment.push_back(inc());
increment[X].u=Cmd[i].up;
increment[X].l=Cmd[i].lw;
increment[X].ctr=1;
X++;
}
}
if(Cmd[i].no==2)
calc(A,Cmd,increment,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<inc> increment;
vector<cmd> Cmd;
X=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,increment,1,M);
for(int i=0;i<increment.size();i++)
{
for(int j=increment[i].l-1;j<increment[i].u;j++)
A[j]=increment[i].ctr;
}
for(int i=0;i<N;i++)
cout<<A.at(i)<<" ";
cout<<endl;
n--;
}
}