QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#67464#2581. 浙江省选alpha102297 403ms12172kbC++143.0kb2022-12-10 16:12:422022-12-10 16:12:45

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-12-10 16:12:45]
  • 评测
  • 测评结果:97
  • 用时:403ms
  • 内存:12172kb
  • [2022-12-10 16:12:42]
  • 提交

answer

#include <cstdio>
#include <cstring>
#include <utility>
#include <algorithm>
using namespace std;
const int N = 1e5;
int n,m;
int ans[N + 5];
struct frac
{
    long long x,y;
    long long z;
    inline frac(long long a = 0,long long b = 1)
    {
        b < 0 && (a = -a,b = -b);
        z = a / b,x = a % b,y = b;
        x < 0 && (x += y,--z);
    }
    inline long long floor()
    {
        return z;
    }
    inline long long ceil()
    {
        return z + (x > 0);
    }
    inline bool operator<=(const frac &o) const
    {
        return z < o.z || (z == o.z && (x * o.y <= o.x * y));
    }
} inter[N + 5];
struct Linear
{
    long long k,b;
    int id;
    inline Linear(long long x = 0,long long y = 0,int z = 0)
    {
        k = x,b = y,id = z;
    }
    inline bool operator<(const Linear &o) const
    {
        return k < o.k || (k == o.k && b > o.b);
    }
} a[N + 5],s[N + 5];
int top;
inline frac intersection(const Linear &a,const Linear &b)
{
    return frac(b.b - a.b,a.k - b.k);
}
pair<long long,int> t[(N << 1) + 5];
int cnt;
void solve(int k)
{
    top = cnt = 0;
    for(register int i = 1;i <= n;++i)
        if(ans[a[i].id] == -1 && (!top || a[i].k > s[top].k))
        {
            for(;top && a[i].b >= s[top].b;--top);
            for(;top > 1 && intersection(a[i],s[top]).floor() < inter[top].ceil();--top);
            s[++top] = a[i];
            top > 1 && (inter[top] = intersection(s[top - 1],s[top]),1);
        }
    inter[top + 1] = frac(1e18,1);
    for(register int i = 1;i <= n;++i)
        if(~ans[a[i].id])
        {
            int l = 1,r = top,mid,L = 0,R = 0;
            while(l <= r)
                mid = l + r >> 1,
                (s[mid].k >= a[i].k || intersection(s[mid],a[i]) <= inter[mid + 1]) ? (L = mid,r = mid - 1) : (l = mid + 1);
            t[++cnt] = make_pair(s[L].k >= a[i].k ? 0 : intersection(s[L],a[i]).floor() + 1,1);
            l = 1,r = top;
            while(l <= r)
                mid = l + r >> 1,
                (s[mid].k <= a[i].k || inter[mid] <= intersection(s[mid],a[i])) ? (R = mid,l = mid + 1) : (r = mid - 1);
            t[++cnt] = make_pair(s[R].k <= a[i].k ? 1e18 + 1 : intersection(s[R],a[i]).ceil(),-1);
        }
    sort(t + 1,t + cnt + 1);
    for(register int i = 1,j = 1,rk = 0;i <= top;++i)
    {
        for(;j <= cnt && t[j].first <= inter[i].ceil();rk += t[j++].second);
        rk == k - 1 && (ans[s[i].id] = k);
        for(register int x;j <= cnt && t[j].first <= inter[i + 1].floor();j = x)
        {
            for(x = j;x <= cnt && t[x].first == t[j].first;rk += t[x++].second);
            rk == k - 1 && (ans[s[i].id] = k);
        }
    }
}
int main()
{
    scanf("%d%d",&n,&m),memset(ans,-1,sizeof ans);
    for(register int i = 1;i <= n;++i)
        scanf("%lld%lld",&a[i].k,&a[i].b),a[i].id = i;
    sort(a + 1,a + n + 1);
    for(register int i = 1;i <= m;++i)
        solve(i);
    for(register int i = 1;i <= n;++i)
        printf("%d%c",ans[i]," \n"[i == n]);
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 10
Accepted
time: 1ms
memory: 9004kb

input:

200 20
999980116 499972659661732832
999976382 499985954590784341
999989500 499925628313372149
999969174 499998188932933085
999993007 499901652814140492
999990405 499919713063836435
999985157 499951191391405214
999988856 499929777538026104
999983505 499959193478550562
999997425 499868325384982983
999...

output:

13 3 1 1 13 1 9 1 1 5 1 4 10 1 2 4 8 8 1 8 2 9 12 8 7 11 1 4 1 18 8 10 7 5 15 17 18 9 5 6 1 8 1 1 1 4 1 6 6 10 5 2 2 1 1 1 1 1 1 1 14 1 5 8 13 2 8 1 1 12 14 7 5 1 19 9 6 1 8 20 8 1 7 6 1 4 4 5 1 1 15 7 -1 1 15 1 11 1 8 1 1 1 1 1 2 1 1 1 3 2 14 1 1 1 2 1 7 4 6 6 1 2 1 5 3 1 13 8 6 20 10 3 1 3 2 5 5 5...

result:

ok 200 numbers

Test #2:

score: 10
Accepted
time: 1ms
memory: 8940kb

input:

200 20
999987497 499948437833472521
999996959 499868998184523935
999994358 499893870645923033
999975699 499997452465640324
999991019 499922692912995747
999995590 499882342299620979
999992660 499908940075973527
999993430 499902451634211649
999988597 499940942406206565
999984338 499966668609284350
999...

output:

6 10 1 1 2 1 15 1 1 10 1 3 11 1 19 6 15 11 1 17 3 2 10 3 2 5 1 16 1 7 10 14 11 8 3 12 7 5 7 4 1 5 5 1 1 2 1 3 20 6 15 3 5 1 3 12 9 1 2 1 8 1 4 8 5 8 3 11 1 9 17 5 3 1 7 9 6 6 4 17 6 1 3 5 1 6 4 13 1 1 12 9 20 3 5 1 4 1 6 1 1 1 1 1 6 1 1 1 5 6 9 1 1 1 8 1 2 5 15 20 1 2 1 12 3 2 7 4 4 15 3 4 1 13 3 17...

result:

ok 200 numbers

Test #3:

score: 10
Accepted
time: 45ms
memory: 9016kb

input:

100000 1
995507459 455461230768415462
992113796 476633897430149354
990046675 486176517140632308
990693952 483456835323367192
992902690 472331671443411224
984426621 499579245114571350
996609686 447080228327473793
996775878 445749287086756631
997240803 441933882373646908
984490644 499532148643458218
9...

output:

-1 -1 1 -1 1 1 1 -1 1 -1 -1 1 -1 -1 -1 -1 -1 1 -1 -1 -1 1 -1 -1 -1 1 1 -1 -1 1 -1 -1 1 -1 -1 1 -1 -1 -1 -1 1 -1 1 -1 -1 1 -1 1 -1 1 -1 1 1 1 -1 -1 -1 -1 1 -1 1 -1 -1 1 1 -1 -1 -1 -1 -1 -1 -1 1 -1 1 -1 -1 1 -1 -1 -1 -1 -1 -1 -1 -1 -1 1 -1 -1 -1 -1 -1 1 -1 -1 -1 1 -1 1 1 1 -1 -1 1 -1 1 -1 -1 -1 -1 -1 ...

result:

ok 100000 numbers

Test #4:

score: 10
Accepted
time: 59ms
memory: 10056kb

input:

100000 2
991412670 480971937820254236
990880886 483399967849466650
990132926 486534602121455050
999529192 422379939305725616
993003091 472698023255462877
984537783 499583410039053084
996659737 447784159070513814
993493013 469843173063053612
997292212 442621199841168574
983882910 499918568849841652
9...

output:

2 -1 1 2 1 1 1 2 1 -1 2 1 2 -1 -1 -1 2 1 -1 2 -1 1 2 -1 2 1 1 2 2 1 2 -1 1 2 2 1 -1 -1 2 2 1 2 1 2 2 1 -1 1 -1 1 -1 1 1 1 -1 -1 -1 2 1 2 1 2 2 1 1 2 2 -1 2 -1 2 2 1 2 1 2 2 1 2 -1 -1 -1 2 2 2 2 2 1 2 -1 2 -1 -1 1 2 -1 -1 1 -1 1 1 1 2 2 1 2 1 2 2 2 2 2 2 1 2 2 -1 1 -1 2 1 -1 2 1 1 -1 -1 -1 2 -1 -1 -1...

result:

ok 100000 numbers

Test #5:

score: 10
Accepted
time: 59ms
memory: 10048kb

input:

100000 2
993979270 465977847440576160
992153425 476514540732474764
990125819 485932319628220600
987618793 494261753424974214
993002754 471860182660680431
984405696 499583238418368572
996693586 446523662746693063
997730070 437915129050162848
997324133 441366872041690270
986522031 496761743896734778
9...

output:

-1 -1 1 2 1 1 1 2 1 -1 2 1 2 -1 -1 2 -1 1 2 2 2 1 2 2 2 1 1 2 2 1 2 -1 1 -1 2 1 2 2 2 2 1 2 1 -1 2 1 2 1 -1 1 2 1 1 1 2 -1 2 -1 1 2 1 2 2 1 1 -1 2 -1 2 2 2 2 1 -1 1 -1 2 1 2 2 2 -1 2 -1 2 2 -1 1 2 2 2 -1 2 1 2 2 2 1 2 1 1 1 2 2 1 -1 1 2 -1 2 2 2 -1 1 2 2 2 1 2 -1 1 -1 -1 1 1 -1 2 -1 2 2 -1 2 -1 2 -1...

result:

ok 100000 numbers

Test #6:

score: 10
Accepted
time: 11ms
memory: 9004kb

input:

2000 20
999690756 499999980079580740
999775793 499873343152178009
999778568 499865302268434254
999995457 498498597452482161
999934310 499038858171140096
999695605 499999606074819495
999737663 499961024493174409
999840451 499619042463667628
999740635 499955554888202950
999985048 498599813549261950
99...

output:

6 10 8 7 11 1 5 1 1 16 1 4 14 1 5 3 5 3 5 4 2 1 10 11 2 1 8 12 1 7 6 1 5 1 1 3 5 1 11 3 5 9 1 5 14 2 4 1 1 6 1 1 11 1 4 3 8 6 1 7 5 3 4 3 5 1 4 1 1 1 4 8 3 1 4 4 5 14 3 1 1 1 3 1 2 1 2 2 3 1 9 1 2 4 6 3 7 1 14 13 1 1 3 1 1 1 1 3 8 13 7 2 8 8 5 1 16 1 3 10 1 1 2 4 3 3 1 5 7 1 1 8 10 5 1 6 6 1 7 11 2 ...

result:

ok 2000 numbers

Test #7:

score: 10
Accepted
time: 6ms
memory: 9084kb

input:

2000 20
999857515 499442217910169774
999996751 498351198778209546
999861982 499416382519409859
999926501 498977495355549205
999912634 499083684501824224
999668735 499999517923456185
999792741 499751161104123027
999822533 499623037584244703
999720860 499950676106935227
999982172 498492522309909939
99...

output:

8 6 8 7 5 1 4 1 1 3 1 5 3 1 10 13 6 2 2 3 3 1 5 5 2 1 14 18 1 9 5 1 3 1 1 5 6 1 5 5 8 3 1 6 7 2 2 1 1 11 1 1 3 1 3 10 4 11 1 3 11 5 2 3 12 1 9 1 1 1 1 3 7 1 8 3 10 5 6 1 1 1 4 1 5 1 2 4 3 1 2 1 10 10 5 5 2 1 8 4 1 1 3 1 1 1 1 10 17 3 2 3 7 7 6 1 2 1 12 2 1 1 5 4 5 2 1 8 7 1 1 1 4 2 1 7 4 1 4 11 4 1 ...

result:

ok 2000 numbers

Test #8:

score: 10
Accepted
time: 331ms
memory: 12068kb

input:

100000 20
994194016 465089019609518895
990601847 484271213013156135
990113877 486298793771901625
998955032 427539093348470820
993022300 472184128416555754
984493251 499592034902389178
996692522 447108384170549374
995241010 458021458320090624
997323314 441964940831884209
985816253 498115041865025080
...

output:

2 7 1 3 1 1 1 2 1 2 2 1 2 2 3 2 2 1 2 2 2 1 2 3 2 1 1 3 3 1 4 3 1 3 3 1 5 5 2 3 1 3 1 2 2 1 4 1 2 1 2 1 1 1 2 3 3 2 1 2 1 2 2 1 1 2 2 3 2 5 3 2 1 5 1 2 3 1 2 2 3 2 4 2 4 4 2 1 2 2 2 5 4 1 3 5 2 1 2 1 1 1 2 3 1 5 1 2 4 4 3 2 9 1 2 2 5 1 2 2 1 3 11 1 1 4 4 5 2 4 4 2 2 2 4 1 1 3 2 4 1 3 1 2 4 2 4 1 3 1...

result:

ok 100000 numbers

Test #9:

score: 10
Accepted
time: 392ms
memory: 12172kb

input:

100000 20
999358080 423877884566661828
988380483 492448813591823441
990186930 486115047228590389
997003638 444740269124513590
993064589 472029894394627734
984550467 499556349874036292
996771536 446611200263825377
984913282 499251341911028111
997409545 441388089558451129
987907757 493789514112618884
...

output:

11 2 1 4 1 1 1 4 1 3 3 1 2 8 4 4 6 1 4 3 4 1 2 2 6 1 1 2 3 1 2 2 1 6 3 1 15 6 2 6 1 2 1 3 5 1 3 1 7 1 2 1 1 1 5 5 3 8 1 2 1 3 4 1 1 2 3 11 3 6 3 8 1 12 1 2 6 1 5 3 5 6 4 4 10 6 2 1 11 7 3 9 3 1 3 5 7 1 3 1 1 1 2 2 1 10 1 3 3 2 10 8 7 1 4 2 7 1 2 2 1 12 5 1 1 5 4 4 4 3 4 4 5 2 11 1 1 2 3 12 1 8 1 6 5...

result:

ok 100000 numbers

Test #10:

score: 10
Accepted
time: 403ms
memory: 12144kb

input:

100000 20
998038972 434931362827770295
989074547 489885992919831175
990136687 485861927989975087
994132971 464750394429605174
992997200 471704021396665443
984525695 499556949147873700
996697926 446219522921688375
984926010 499207489074422449
997339652 440952463300399554
984695846 499421070165356264
...

output:

6 3 1 4 1 1 1 3 1 3 5 1 5 5 2 2 3 1 2 4 2 1 4 5 4 1 1 4 5 1 2 6 1 3 3 1 2 4 4 5 1 3 1 4 3 1 8 1 4 1 9 1 1 1 4 5 10 4 1 5 1 4 3 1 1 3 2 6 2 6 2 7 1 5 1 5 5 1 3 3 4 2 3 3 3 12 2 1 2 4 10 6 2 1 2 3 4 1 2 1 1 1 2 5 1 4 1 5 3 4 3 3 6 1 6 2 4 1 4 12 1 2 2 1 1 2 4 8 2 2 2 5 5 4 2 1 1 2 5 3 1 6 1 2 3 2 3 1 ...

result:

ok 100000 numbers

Extra Test:

score: -3
Extra Test Failed : Wrong Answer on 2
time: 1ms
memory: 8948kb

input:

3000 20
16 99990689
6 99995379
62 99994106
1 99991185
13 99995758
33 99995727
44 99994797
93 99999595
71 99995375
27 99994810
40 99994282
54 99991237
2 99993339
100 99995110
56 99995328
15 99998010
54 99997356
1 99993862
100 99998770
72 99992148
23 99999271
33 99996542
53 99997045
39 99993665
21 999...

output:

-1 -1 -1 -1 -1 -1 -1 19 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 5 -1 -1 -1 -1 -1 -1 -1 -1 -1 2 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 16 -1 -1 -1 -1 -1 -1 -1 -1...

result:

wrong answer 659th numbers differ - expected: '14', found: '19'