QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#53515#434. 密码not_so_organic100 ✓12ms4224kbC++3.9kb2022-10-05 12:43:122022-10-05 12:43:14

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-10-05 12:43:14]
  • 评测
  • 测评结果:100
  • 用时:12ms
  • 内存:4224kb
  • [2022-10-05 12:43:12]
  • 提交

answer

//Orz dls! dlstxdy!
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ui unsigned int
#define ull unsigned ll
#define pii pair<int,int>
#define pll pair<ll,ll>
#define db long double
#define mp make_pair
#define X first
#define Y second
#define vi vector<int>
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,b,a) for(int i=(b);i>=(a);--i)
#define rep0(i,a,b) for(int i=(a);i<(b);++i)
#define fore(i,a) for(int i=0;i<(a).size();++i)
#define ls x<<1,l,m
#define rs x<<1|1,m+1,r
#define gc getchar
inline ll rd() {
    ll x = 0, w = 1;
    char c = gc();

    while (!isdigit(c) && c != '-')
        c = gc();

    if (c == '-')
        c = gc(), w = -1;

    while (isdigit(c))
        x = x * 10 + c - 48, c = gc();

    return x * w;
}
const int N = 2005;
#define pll pair<ll,ll>
int m;
ll P, T, a[N], b[N], c[N];
vector<pll> merge(vector<pll>a, vector<pll>b) {
    int cnt = 0;
    vector<pll>V, ans;

    for (auto x : a)
        V.pb(mp(x.X, -1)), V.pb(mp(x.Y + 1, 1));

    for (auto x : b)
        V.pb(mp(x.X, -1)), V.pb(mp(x.Y + 1, 1));

    inplace_merge(V.begin(), V.begin() + 2 * a.size(), V.end());

    fore(i, V)if ((cnt -= V[i].Y) == 2)
        ans.pb(mp(V[i].X, V[i + 1].X - 1));

    return ans;
}
void calc(ll l, ll r, ll A, ll d, int t, vector<pll> &ans) {
    db td = d + floor((db)l * A / P - 1) * P;
    db dl = td - (db)t * (T / 2), dr = td + (db)t * (T / 2);

    while (dl / A <= r) {
        if (dr / A >= l)
            ans.pb(mp((ll)(dl / A), (ll)(dr / A)));

        dl += P;
        dr += P;
    }
}
inline ll mul(ll a, ll b) {
    return (a * b - (ll)((db)a * b / P + 0.05) * P + P) % P;
}
inline ll pw(ll a, ll b) {
    ll r = 1;

    for (; b; b >>= 1, a = mul(a, a))
        if (b & 1)
            r = mul(r, a);

    return r;
}
inline bool chk(ll x) {
    rep0(i, 0, m) {
        ll r = (b[i] + P - mul(x, a[i]) + T / 2) % P;

        if (r > T)
            return 0;
    }
    return 1;
}
struct st {
    ll a, l, o;
};
inline bool operator==(const st &x, const st &y) {
    return x.a == y.a && x.l == y.l && x.o == y.o;
}
inline bool operator<(const st &x, const st &y) {
    return x.a < y.a;
}
vector<st>Eq[10];
void sol() {
    m = rd();
    P = rd();
    T = rd();
    rep0(i, 0, m)c[i] = rd(), b[i] = rd();
    ll d = pw(c[0], P - 2);
    rep0(i, 0, m)a[i] = mul(c[i], d);
    vector<st>E;

    rep0(i, 1, m)if (rand() & 1)
        E.pb((st) {
        a[i], b[i], 1
    });
    else
        E.pb((st) {
        P - a[i], P - b[i], 1
    });
    sort(E.begin(), E.end());
    rep0(i, 0, 5) {
        int nn = E.size();

        rep0(i, 0, nn)rep0(j, i + 1, min(i + 5, nn))if (E[i].a != E[j].a)
            E.pb((st) {
            E[j].a - E[i].a, (E[j].l + P - E[i].l) % P, E[j].o + E[i].o
        });

        if (E.size() > 400) {
            nth_element(E.begin(), E.begin() + 400, E.end());
            E.erase(E.begin() + 400, E.end());
        }

        sort(E.begin(), E.end());
        E.erase(unique(E.begin(), E.end()), E.end());

        if (E.size() > 300)
            E.resize(300);

        Eq[i] = E;
    }
    vector<pll>ans;
    calc(b[0] + P - T / 2, b[0] + P + T / 2, E[0].a, E[0].l, E[0].o, ans);
    per(t, 4, 0) {
        E = Eq[t];
        rep(i, 1, 10) {
            ll s = 0;
            fore(j, ans)s += ans[j].Y - ans[j].X + 1;

            if (s < 100)
                break;

            vector<pll>V;
            fore(j, ans)calc(ans[j].X, ans[j].Y, E[i].a, E[i].l, E[i].o, V);
            ans = merge(ans, V);
        }
    }

    fore(i, ans)for (ll x = ans[i].X; x <= ans[i].Y; x++)
        if (chk(x))
            printf("%lld\n", mul(x, d));
}
int main() {
    int TT = rd();

    while (TT--)
        sol();

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 10
Accepted
time: 2ms
memory: 3920kb

input:

5
50 957125670377996927 1000000
585945225866084424 54589429123661916
573947126284093449 777559102750892238
153166610639441991 900505234633730119
829276546475860347 938947033720938303
667383545481941162 128214790654861522
642730062581689305 607900221293886873
386770285184824777 896008952335357488
399...

output:

557534539406344445
48614680453513616
171635259452156428
510374952494623520
577639061489488455

result:

ok 5 lines

Test #2:

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

input:

5
50 985780537212717349 100000000
930098920826707192 859185097554991862
114822564798967594 461663135509764494
290070133363935573 237203042621528977
876169993923548070 273892762234612214
946247278327197064 419030027202401205
613487802603166556 236215096880543712
249116322858554956 901707011293379960
...

output:

728806913399199677
304868452402743224
697338918497266871
845921715720531367
470978095570778021

result:

ok 5 lines

Test #3:

score: 10
Accepted
time: 3ms
memory: 3892kb

input:

5
50 912737338345705547 100000000000
560012542306640281 862559101259689768
518735103494826790 725717349992961571
733957671413353056 169708736886932691
847743526385447667 828696564841332397
107464092562234365 59619590616607389
12132877913647855 720538986960211892
612839049922974832 392264373061240257...

output:

667097255749051439
24610618949224203
416899801207925772
297738252979447312
23941143985346380

result:

ok 5 lines

Test #4:

score: 10
Accepted
time: 3ms
memory: 3828kb

input:

5
50 923097614961380909 1000000000000
97787754875250907 894771248217970266
776694885545580577 777083965073479575
75664239830708863 608716256879701985
237252054800496293 227374993084820963
863032115948152221 365706449805636266
24225822787011794 79303911682790301
773238132021550432 520965679721963390
...

output:

393439798021650097
806593912421988792
494092519607999744
760635090566656810
345872402107725664

result:

ok 5 lines

Test #5:

score: 10
Accepted
time: 12ms
memory: 4180kb

input:

5
2000 9342566358299507 93425663582995
6219101435016694 607891369107000
2117136321762304 2881084573543566
5176682988483854 9306200956208720
8253904804096661 3103523256778684
781386676390747 6601635146687045
6181577982870712 4562900022641750
771036361995174 8802607411541107
8287347227209040 478889400...

output:

8024221318134640
2912294945052670
923582019125464
5148136834097532
5126098831270182

result:

ok 5 lines

Test #6:

score: 10
Accepted
time: 10ms
memory: 4224kb

input:

5
2000 9076941054068597 90769410540685
4164033048333799 6936964960910632
3199151620643150 6169865631753216
3651033776359505 2974612359357727
2437435894180490 7336869581147738
5545756515709013 7225793088900941
316850256662501 598866992420596
1931439899610976 2903969210506357
8802893275621192 51018944...

output:

1049242800759464
8098010761231495
6576281651256434
8788103720252148
3573052280622623

result:

ok 5 lines

Test #7:

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

input:

5
50 986015706540181189 9860157065401811
472447084034094466 701096881178679368
789872459992477277 285017390663914121
139210847563896009 338277635649123845
434174656592580245 368068516438243771
537010852985895475 932180742287574181
420177119220393796 66137395305182219
278267742669272495 2098294852103...

output:

247849421175747134
100544625964575839
218474019585825000
853233263834273947
150488072330948426

result:

ok 5 lines

Test #8:

score: 10
Accepted
time: 5ms
memory: 4076kb

input:

5
50 937539041569299811 9375390415692998
243699599186989388 703817656494514633
490867383683796688 57336497141264681
700995121811059804 884266519548391255
881486531050497524 858417683373541541
483378074519689731 77311461506286120
163799445567955662 630863894729944525
440743631644571023 63661909944717...

output:

480527239412739446
240239983899314410
717198444316236280
414802198647450124
760614208963438868

result:

ok 5 lines

Test #9:

score: 10
Accepted
time: 7ms
memory: 4184kb

input:

5
50 956768533438862867 9567685334388628
159562951002452715 368735031805266874
168203674133135151 519955057721789995
47311303546279427 578468091719224380
488003044752475047 477936813372989614
937035830526454154 585363966735703129
36829830576452586 103584638478504234
938044828907421065 95216503175921...

output:

872783696595005529
170623286712767189
171378135465905434
354338605103736188
412064789025078524

result:

ok 5 lines

Test #10:

score: 10
Accepted
time: 3ms
memory: 4020kb

input:

5
50 954878053655579819 9548780536555798
547909457155842874 765505419310330784
582173103744680117 218053461605844877
290855470787761778 22535982680457566
488260659830503816 201490530306797340
811716163899850400 660850073720225447
662289272267072258 744062472352240699
397407312047625799 2689240086486...

output:

300091718525150102
452635639856590776
679925824089959032
367418322249800717
601189687672072278

result:

ok 5 lines

Extra Test:

score: 0
Extra Test Passed