QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#709055 | #6703. Tokens on the Segments | futarian | RE | 0ms | 0kb | C++14 | 912b | 2024-11-04 11:05:16 | 2024-11-04 11:05:17 |
answer
#include "bits/stdc++.h"
using namespace std;
const int Len = 1e5 + 5;
int n,m;
struct Seg
{
int l,r;
Seg(){l = r = 0;}
Seg(int L,int R){l = L , r = R;}
}seg[Len];
inline bool cmp(Seg x,Seg y){return x.l < y.l;}
signed main()
{
int T;scanf("%d",&T);
while(T --)
{
priority_queue<int,vector<int>,greater<int>> Q;
scanf("%d",&n);
for(int i = 1 ; i <= n ; i ++) scanf("%d %d",&seg[i].l,&seg[i].r);
sort(seg + 1 , seg + 1 + n , cmp);
int now = 0 , id = 1 , as = 0 , i = 1;
while(1)
{
while(id <= n && seg[i].l <= now + 1)
{
Q.push(seg[i].r);
i ++;
}
while(!Q.empty() && Q.top() <= now) Q.pop();
if(!Q.empty())
{
now ++;
Q.pop();
as ++;
}
else
{
if(i <= n)
{
now = seg[i].l;
as ++;
i ++;
}
}
if(i >= n + 1 && Q.empty()) break;
}
printf("%d\n",as);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Runtime Error
input:
2 3 1 2 1 1 2 3 3 1 2 1 1 2 2