QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#709074 | #6703. Tokens on the Segments | futarian | WA | 106ms | 4832kb | C++11 | 934b | 2024-11-04 11:13:47 | 2024-11-04 11:13:48 |
Judging History
answer
#include "bits/stdc++.h"
using namespace std;
const int Len = 1e5 + 5;
int n,m;
struct Segmt
{
int l,r;
Segmt(){l = r = 0;}
Segmt(int L,int R){l = L , r = R;}
}seg[Len];
bool cmp(Segmt x,Segmt y){return x.l < y.l && (x.l == y.l && x.r < y.r);}
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 , as = 0 , i = 1;
while(1)
{
while(i <= 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: 100
Accepted
time: 1ms
memory: 4540kb
input:
2 3 1 2 1 1 2 3 3 1 2 1 1 2 2
output:
3 2
result:
ok 2 number(s): "3 2"
Test #2:
score: -100
Wrong Answer
time: 106ms
memory: 4832kb
input:
10000 6 5 19 7 12 10 10 4 14 1 12 5 11 7 3 5 1 10 12 15 2 13 8 11 5 20 11 14 18 6 17 6 9 6 20 2 7 1 11 16 19 2 5 1 14 5 8 14 19 4 7 11 19 11 13 2 9 3 12 12 13 19 19 13 16 11 11 13 1 2 14 17 15 16 12 17 15 17 6 7 8 11 12 19 3 8 10 19 18 6 9 16 18 13 15 14 15 9 13 2 8 12 18 8 16 16 18 3 18 1 12 4 13 1...
output:
6 6 4 7 8 7 7 2 10 2 4 5 7 6 6 4 9 5 4 5 4 4 5 12 4 7 3 3 7 2 2 3 7 3 10 3 5 8 4 6 4 3 5 4 6 10 8 7 8 7 3 3 8 5 8 7 11 2 11 4 7 9 4 4 6 5 7 9 3 4 3 2 7 6 3 7 5 7 6 3 5 7 5 10 10 7 5 7 4 5 2 8 4 2 11 6 8 6 4 9 8 6 3 4 7 5 8 11 3 7 6 2 6 5 7 3 5 8 9 4 10 12 6 7 6 6 8 8 5 7 4 7 2 10 10 6 5 10 7 8 6 2 5...
result:
wrong answer 2nd numbers differ - expected: '7', found: '6'