-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1.cpp
More file actions
64 lines (56 loc) · 1 KB
/
1.cpp
File metadata and controls
64 lines (56 loc) · 1 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
#include<bits/stdc++.h>
using namespace std;
struct entry
{
int s;
int e;
int index;
entry(int s, int e, int index): s(s), e(e),index(index){}
};
struct Compare{
bool operator()(entry const& e1,entry const& e2)
{
return((e1.s > e2.s)|| (e1.s==e2.s && e1.index > e2.index));
}
};
priority_queue<entry, vector<entry>, Compare> Q;
queue<int> result;
void gets_when(priority_queue<entry, vector<entry>, Compare> Q, int size)
{
int time = 0;
while(!Q.empty())
{
entry top = Q.top();
//cout<<top.s<<" "<<top.e<<endl;
if(top.s > time) {time = top.s; result.push(time);}
else if( (top.s <= time) && (top.e > time))
{time=time+1; result.push(time);}
else {result.push(0);}
Q.pop();
}
}
int main()
{
int t;
cin>>t;
for(int i=0;i<t;i++)
{
int n;
cin>>n;
int l, r;
for(int j = 0; j <n; j++)
{
cin>>l>>r;
Q.push(entry(l,r,j));
}
gets_when(Q,n);
while(!Q.empty())
{ Q.pop();}
while(n>0)
{ n--;
cout<<result.front()<<" ";
result.pop();
}
cout<<endl;
}
}