QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#555392#3101. Event Hopping 2cocoa_chan0 140ms114364kbC++173.9kb2024-09-09 22:23:262024-09-09 22:23:29

Judging History

你现在查看的是最新测评结果

  • [2024-09-09 22:23:29]
  • 评测
  • 测评结果:0
  • 用时:140ms
  • 内存:114364kb
  • [2024-09-09 22:23:26]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll siz=262144;
const ll inf=1e18;
ll n,m,i,j,k,l,r,x,y,z,w,s,t,a[1100000],seg[1100000],lazy[1100000],e,ee,sparse[31][220000],cur,mn,asdf,ans[1100000];
set<ll> le,ri;
pair<ll,ll> p[1100000],q[1100000];
vector<ll> u,v[1100000];
void propagate(ll x,ll y,ll z)
{
    if(z<siz)
    {
        lazy[z*2]+=lazy[z];
        lazy[z*2+1]+=lazy[z];
    }
    seg[z]+=lazy[z];
    lazy[z]=0;
}
void f(ll x,ll y,ll z,ll w)
{
    propagate(x,y,z);
    if(l>y||x>r)
        return;
        if(l<=x&&y<=r)
        {
            lazy[z]+=w;
            propagate(x,y,z);
            return;
        }
    f(x,(x+y)/2,z*2,w);
    f((x+y)/2+1,y,z*2+1,w);
    seg[z]=seg[z*2]+seg[z*2+1];
}
ll g(ll x,ll y,ll z)
{
    propagate(x,y,z);
    if(l>y||x>r)
        return 0;
    if(l<=x&&y<=r)
        return seg[z];
    return g(x,(x+y)/2,z*2)+g((x+y)/2+1,y,z*2+1);
}
ll interval(ll x,ll y)
{
    ll e=30,s=0;
    while(e>=0)
    {
        if(sparse[e][x]<=y)
        {
            s+=1<<e;
           // printf("(%lld:%lld,%lld)",x,e,sparse[e][x]);
            x=sparse[e][x];
        }
        e--;
    }
    return s;
}
ll inthere(ll x,ll y)
{
    l=x;
    r=y;
    return g(1,siz,1);
}
ll prv(ll x)
{
    return *(--ri.lower_bound(x));
}
ll nxt(ll x)
{
    //printf("[%lld:%lld]\n",x,*(le.lower_bound(x+1)));
    return *(le.lower_bound(x+1));
}
void add(ll x,ll y)
{
    le.insert(x);
    ri.insert(y);
    l=x;
    r=y;
    f(1,siz,1,1);
}
int main()
{

    scanf("%lld %lld",&n,&k);
    le.insert(2*n+3);
    ri.insert(0);
    for(i=1;i<=n;i++)
    {
        scanf("%lld %lld",&x,&y);
        y--;
        u.push_back(x);
        u.push_back(y);
        p[i]={x,y};
    }
    sort(u.begin(),u.end());
    u.erase(unique(u.begin(),u.end()),u.end());
    for(i=1;i<=n;i++)
    {
        p[i].first=lower_bound(u.begin(),u.end(),p[i].first)-u.begin()+2;
        p[i].second=lower_bound(u.begin(),u.end(),p[i].second)-u.begin()+2;
        x=p[i].first;
        y=p[i].second;
        q[i]={y,x};
    }
    sort(q+1,q+n+1);
    for(i=1;i<=n;i++)
        swap(q[i].first,q[i].second);
    for(i=1;i<=n;i++)
    {
     //   printf("(%lld,%lld)\n",q[i].first,q[i].second);
    }
    for(i=1;i<=n;i++)
    {
        v[q[i].first].push_back(i);
    }
    mn=2*n+4;
    cur=2*n+4;
    q[2*n+4]={2*n+3,2*n+3};
    sparse[0][2*n+4]=2*n+4;
    q[0]={1,1};
    for(i=n*2+3;i>=1;i--)
    {
        x=i;
        for(auto xx:v[i+1])
        {
            if(mn>q[xx].second)
            {
                mn=q[xx].second;
                cur=xx;
            }
        }
     //   printf("(%lld:%lld)\n",i,cur);
        sparse[0][i]=mn;
    }
    /*for(i=1;i<=2*n+4;i++)
        printf("(%lld)",sparse[e][i]);
    printf("\n");
    */for(e=1;e<=30;e++)
    {
        for(i=1;i<=n*2+4;i++)
        {
            sparse[e][i]=sparse[e-1][min(sparse[e-1][i],2*n+4)];
      //      printf("(%lld)",sparse[e][i]);
        }
       // printf("\n");
    }
    //printf("?");
    if(interval(1,2*n+2)<k)
    {
   //     printf("(%lld)",interval(1,2*n+2));
        printf("-1");
        return 0;
    }
    m=k;
    t=interval(1,2*n+2);
    //printf("%lld\n",t);
    cur=0;
    for(i=1;i<=n;i++)
    {
      //  printf("(%lld)\n",i);
        x=p[i].first;
        y=p[i].second;
        if(inthere(x,y))
            continue;
        z=prv(x);
        w=nxt(y);
       // printf("(%lld,%lld(%lld),%lld,%lld(%lld),%lld,%lld(%lld))",z+1,w-1,interval(z+1,w-1),z+1,x-1,interval(z+1,x-1),y+1,w-1,interval(y+1,w-1));
        asdf=-interval(z+1,w)+interval(z+1,x)+interval(y+1,w)+1;
        s=t+asdf+cur;
        if(s>=k)
        {
            t+=asdf;
            cur++;
            ans[cur]=i;
            add(x,y);
        }
    }
    for(i=1;i<=k;i++)
    {
        printf("%lld\n",ans[i]);
    }
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 7
Accepted
time: 3ms
memory: 91548kb

input:

1 1
1 3

output:

1

result:

ok single line: '1'

Test #2:

score: 7
Accepted
time: 12ms
memory: 92904kb

input:

2 1
2 4
3 7

output:

1

result:

ok single line: '1'

Test #3:

score: 7
Accepted
time: 7ms
memory: 91912kb

input:

3 1
2 5
3 5
4 7

output:

1

result:

ok single line: '1'

Test #4:

score: 0
Wrong Answer
time: 140ms
memory: 114364kb

input:

99999 93097
40044 40749
44538 45365
46530 47401
52845 53481
59519 60065
86226 87059
88353 88992
95665 96502
95669 96575
100446 100968
121870 122544
130836 131540
146294 147230
151177 151970
160381 161376
164174 165119
166582 167438
169062 169687
173200 173849
177329 178217
189213 189811
249372 25029...

output:

7
8
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
48
49
50
51
52
53
54
55
56
57
59
60
61
62
64
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
109
110
1...

result:

wrong answer 1st lines differ - expected: '1', found: '7'

Subtask #2:

score: 0
Wrong Answer

Test #47:

score: 1
Accepted
time: 3ms
memory: 91628kb

input:

1 1
134842099 137944073

output:

1

result:

ok single line: '1'

Test #48:

score: 1
Accepted
time: 3ms
memory: 90632kb

input:

2 2
4015595 884953730
519508315 726912949

output:

-1

result:

ok single line: '-1'

Test #49:

score: 1
Accepted
time: 0ms
memory: 92660kb

input:

3 2
551691302 800582045
14063803 52897269
153641504 567834643

output:

1
2

result:

ok 2 lines

Test #50:

score: 1
Accepted
time: 0ms
memory: 91248kb

input:

18 3
157893686 958635898
790021767 976682032
534783017 706987897
216566011 510148270
288661613 856715472
81126924 420966670
9734253 823219818
77427078 241270378
182953794 928971032
65710916 937359407
159217847 343023570
266169092 635952191
94867522 407392584
298640819 490028599
281580042 514089998
6...

output:

2
3
4

result:

ok 3 lines

Test #51:

score: 1
Accepted
time: 4ms
memory: 92684kb

input:

19 3
345121760 363569961
369142474 697961114
204455374 777512357
278051598 780834857
119744682 610142516
112692534 284271720
530820418 613805256
666599238 970772442
684066330 747151742
52464000 153949333
361766230 921325388
34600363 168745634
119418778 738281466
828841976 976561834
257913352 2579536...

output:

1
2
6

result:

ok 3 lines

Test #52:

score: 0
Wrong Answer
time: 3ms
memory: 91200kb

input:

20 3
226617517 417144410
401110226 504506272
204308913 972565478
100780114 930332684
473716139 730386187
327436800 871728821
662616072 881801440
469971234 769277127
437331467 913865677
641546412 700063729
82089639 830256714
384651823 502387376
558881974 905373190
468189379 998408858
9103683 60217281...

output:

7
12
0

result:

wrong answer 1st lines differ - expected: '1', found: '7'

Subtask #3:

score: 0
Wrong Answer

Test #74:

score: 0
Wrong Answer
time: 4ms
memory: 91844kb

input:

3000 57
226083340 261990234
392684356 462929590
468018811 841719892
495096853 606046097
196983814 256423598
331199122 967656486
802593662 931108452
74501453 679054962
294344294 752837262
295708332 547261648
265421699 652708933
272959087 727136240
165667761 846917534
61770748 157663302
608516043 8492...

output:

50
54
85
100
104
139
146
151
160
224
228
237
257
265
297
308
347
401
543
599
665
683
686
766
811
971
990
1136
1508
1670
1676
1774
2153
2593
2608
2695
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

result:

wrong answer 2nd lines differ - expected: '85', found: '54'

Subtask #4:

score: 0
Wrong Answer

Test #111:

score: 0
Wrong Answer
time: 104ms
memory: 107284kb

input:

100000 361
136798318 785362988
255943758 535488232
175203444 266819907
766993466 893575347
67274251 589651108
662289594 883406317
830803801 849703610
729398668 798198453
202605534 677648797
66407931 925909114
174421361 601553812
522629146 701284080
136544340 295925673
299796891 499869765
736583725 8...

output:

42
102
155
185
215
239
279
289
599
660
797
811
950
957
1006
1156
1247
1623
1655
1820
1939
1980
2088
2356
2383
2396
2473
2487
2701
3016
3048
3096
3107
3194
3235
3257
3462
3729
3831
3924
3986
4119
4354
4462
4677
4743
4879
4968
5204
5206
5229
5255
5656
5681
5684
5703
5843
5889
5901
5924
5934
6013
6049
...

result:

wrong answer 3rd lines differ - expected: '185', found: '155'