QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#420004#1060. 快速查询Max_s_xaM100 ✓666ms8580kbC++174.3kb2024-05-24 13:47:212024-05-24 13:47:22

Judging History

This is the latest submission verdict.

  • [2024-05-24 13:47:22]
  • Judged
  • Verdict: 100
  • Time: 666ms
  • Memory: 8580kb
  • [2024-05-24 13:47:21]
  • Submitted

answer

#include <iostream>
#include <algorithm>

typedef long long ll;
typedef double lf;

// #define DEBUG 1
struct IO
{
    #define MAXSIZE (1 << 20)
    #define isdigit(x) (x >= '0' && x <= '9')
    char buf[MAXSIZE], *p1, *p2;
    char pbuf[MAXSIZE], *pp;
    #if DEBUG
    #else
    IO() : p1(buf), p2(buf), pp(pbuf) {}
    ~IO() {fwrite(pbuf, 1, pp - pbuf, stdout);}
    #endif
    #define gc() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, MAXSIZE, stdin), p1 == p2) ? ' ' : *p1++)
    #define blank(x) (x == ' ' || x == '\n' || x == '\r' || x == '\t')

    template <typename T>
    void Read(T &x)
    {
        #if DEBUG
        std::cin >> x;
        #else
        bool sign = 0; char ch = gc(); x = 0;
        for (; !isdigit(ch); ch = gc())
            if (ch == '-') sign = 1;
        for (; isdigit(ch); ch = gc()) x = x * 10 + (ch ^ 48);
        if (sign) x = -x;
        #endif
    }
    void Read(char *s)
    {
        #if DEBUG
        std::cin >> s;
        #else
        char ch = gc();
        for (; blank(ch); ch = gc());
        for (; !blank(ch); ch = gc()) *s++ = ch;
        *s = 0;
        #endif
    }
    void Read(char &c) {for (c = gc(); blank(c); c = gc());}

    void Push(const char &c)
    {
        #if DEBUG
        putchar(c);
        #else
        if (pp - pbuf == MAXSIZE) fwrite(pbuf, 1, MAXSIZE, stdout), pp = pbuf;
        *pp++ = c;
        #endif
    }
    template <typename T>
    void Write(T x)
    {
        if (x < 0) x = -x, Push('-');
        static T sta[35];
        int top = 0;
        do sta[top++] = x % 10, x /= 10; while (x);
        while (top) Push(sta[--top] ^ 48);
    }
    template <typename T>
    void Write(T x, char lst) {Write(x), Push(lst);}
} IO;
#define Read(x) IO.Read(x)
#define Write(x, y) IO.Write(x, y)
#define Put(x) IO.Push(x)

using namespace std;

const int MAXN = 1e5 + 10, mod = 1e7 + 19;

int n, q, T, at[MAXN], bt[MAXN];
int tmp[MAXN], tot;
struct Qry
{
    int op, x, y;
}qt[MAXN];

inline ll Qpow(ll x, int y = mod - 2) {ll res = 1; while (y) (y & 1) && (res = res * x % mod), x = x * x % mod, y >>= 1; return res;}

ll pmdf[MAXN]; int pt[MAXN];

int main()
{
    // freopen("A.in", "r", stdin);
    // freopen("A.out", "w", stdout);
    #if DEBUG
    #else
    ios::sync_with_stdio(0), cin.tie(0);
    #endif

    Read(n), Read(q);
    for (int i = 1; i <= q; i++)
    {
        Read(qt[i].op);
        if (qt[i].op != 6) Read(qt[i].x);
        if (qt[i].op == 1) Read(qt[i].y), qt[i].y %= mod;
        if (qt[i].op >= 2 && qt[i].op <= 4) qt[i].x %= mod;
        if (qt[i].op == 1 || qt[i].op == 5) tmp[++tot] = qt[i].x;
    }
    sort(tmp + 1, tmp + tot + 1), tot = unique(tmp + 1, tmp + tot + 1) - tmp - 1;
    for (int i = 1; i <= q; i++)
        if (qt[i].op == 1 || qt[i].op == 5) qt[i].x = lower_bound(tmp + 1, tmp + tot + 1, qt[i].x) - tmp;
    Read(T);
    for (int i = 1; i <= T; i++) Read(at[i]), Read(bt[i]);

    ll sum = 0, ans = 0;
    ll mdf = 0, mul = 1, add = 0; int gt = 0, cur = 0;
    for (int u = 1; u <= T; u++)    
        for (int v = 1; v <= q; v++)
        {
            int p = (at[u] + (ll)bt[u] * v) % q + 1; cur++;
            if (qt[p].op == 1)
            {
                sum = (sum - (pt[qt[p].x] < gt ? mdf * mul + add : pmdf[qt[p].x] * mul + add)) % mod;
                pt[qt[p].x] = cur, pmdf[qt[p].x] = (qt[p].y - add) * Qpow(mul) % mod;
                sum = (sum + qt[p].y) % mod;
            }
            else if (qt[p].op == 2)
            {
                add = (add + qt[p].x) % mod;
                sum = (sum + (ll)qt[p].x * n) % mod;
            }
            else if (qt[p].op == 3)
            {
                mul = mul * qt[p].x % mod, add = add * qt[p].x % mod;
                sum = sum * qt[p].x % mod;
            }
            else if (qt[p].op == 4)
            {
                mdf = qt[p].x, gt = cur, mul = 1, add = 0;
                sum = (ll)qt[p].x * n % mod;
            }
            else if (qt[p].op == 5)
            {
                ans = (ans + (pt[qt[p].x] < gt ? mdf * mul + add : pmdf[qt[p].x] * mul + add)) % mod;
            }
            else
            {
                ans = (ans + sum) % mod;
            }
        }
    cout << (ans + mod) % mod << '\n';
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 50
Accepted

Test #1:

score: 50
Accepted
time: 42ms
memory: 8580kb

input:

452026
95958
1 285703 217433997
1 11660 355946119
1 154677 958212086
1 45777 559001183
1 149425 708949937
1 199039 -627813211
1 421465 878181683
1 18566 -840518154
1 268546 -956473636
1 6627 -168874651
1 165349 796846652
1 389787 -241387034
2 856579071
2 776291767
1 361873 220652502
1 34945 3586417
...

output:

7032812

result:

ok single line: '7032812'

Test #2:

score: 50
Accepted
time: 46ms
memory: 7912kb

input:

483072
93455
3 127269075
1 302644 -819206705
1 324283 176567456
1 362914 -123696183
1 269012 35941289
1 320675 371602507
2 621029853
1 261791 42607160
1 134081 -311548238
1 39566 -639742963
1 148195 248115767
2 698644799
1 14757 -854683791
3 568083880
4 -307679829
1 81614 58671469
4 -123658687
1 263...

output:

4330039

result:

ok single line: '4330039'

Test #3:

score: 50
Accepted
time: 48ms
memory: 8180kb

input:

451320
98796
1 273886 584382657
1 72767 882120348
2 -500581825
1 371431 -890794733
1 388789 575894740
1 416938 55821666
4 -139712863
1 391097 644330384
2 -469419669
1 448782 107966848
1 235509 -986289
3 -858374275
1 123585 -837984190
2 929586510
6
1 401033 363310883
1 331019 468451209
1 96904 -12761...

output:

2444116

result:

ok single line: '2444116'

Test #4:

score: 50
Accepted
time: 48ms
memory: 7840kb

input:

482366
98045
1 24349 377283548
1 453704 -854792539
6
1 237007 242624318
1 88252 393839755
6
1 228412 125093668
1 181999 240899085
4 -558162897
1 206599 674854997
1 277268 -501664106
4 -725152265
1 108652 -772913438
1 314782 64055034
1 188046 -600981194
1 351594 751311220
1 27428 454875485
1 435918 -...

output:

1089463

result:

ok single line: '1089463'

Test #5:

score: 50
Accepted
time: 45ms
memory: 7808kb

input:

482013
91226
4 725259386
1 43639 194616618
4 -37234157
1 133414 -574368751
1 86430 -490776890
1 41779 -149936319
1 155135 -789189968
1 23506 90866624
1 173870 866781461
1 357433 -571999918
1 87765 -307392425
5 175104
1 230280 -534700699
1 246779 348430587
4 614286356
1 455152 -217613300
1 91751 6252...

output:

2809378

result:

ok single line: '2809378'

Subtask #2:

score: 50
Accepted

Dependency #1:

100%
Accepted

Test #6:

score: 50
Accepted
time: 666ms
memory: 7920kb

input:

932633695
99894
1 817597654 58755520
1 830426120 -575569935
1 219698976 11255802
6
1 879216899 -243126660
4 778062635
1 614037672 -8450346
1 867388106 702693200
1 383979273 190017535
6
1 31373926 826414468
1 498056404 219646389
4 -534017693
1 364133037 733160350
2 -117264984
2 768406768
6
1 16132616...

output:

6837626

result:

ok single line: '6837626'

Test #7:

score: 50
Accepted
time: 642ms
memory: 8028kb

input:

957779956
94827
3 601355317
1 45079147 38155506
1 231631228 -362057428
6
2 -283829750
6
1 577666590 -691353274
1 205440460 -667647306
1 949397227 -3792339
1 653527564 828820694
1 491521243 915189166
3 -230329676
1 268381062 597296274
4 12779460
1 599484650 351024349
1 896651645 722621340
1 134125930...

output:

4070758

result:

ok single line: '4070758'

Test #8:

score: 50
Accepted
time: 640ms
memory: 7800kb

input:

987958964
92325
2 -468910483
6
1 510389535 900881564
4 -943881278
1 120113253 5273740
1 401108682 -866524220
1 108908755 -622968084
1 690649880 -664653909
6
1 406048569 930927819
5 688114677
4 -245255661
5 105555975
1 353750321 -466163361
5 927730102
6
5 534739635
5 444272952
1 66866280 470469397
1 ...

output:

7152858

result:

ok single line: '7152858'

Test #9:

score: 50
Accepted
time: 664ms
memory: 8008kb

input:

913105224
97665
1 588154473 218605071
1 628019257 213691408
6
2 678329170
2 -538647151
1 545477538 -779883649
1 799854288 -111616832
1 26866293 32675018
2 -340866521
1 124213553 384460066
1 775180734 414347048
2 123715231
1 628324808 -102971256
1 214563428 8068862
1 402502072 -706040775
1 659051837 ...

output:

9405271

result:

ok single line: '9405271'

Test #10:

score: 50
Accepted
time: 647ms
memory: 7896kb

input:

943284232
95163
4 -852531875
1 201974707 -653053877
1 823113651 196429318
3 337869540
1 647936647 114651757
1 593910554 120551408
1 315182996 -77867126
1 812178266 287556917
1 697126470 302117687
1 156012320 687964917
1 670615234 784564862
1 361379363 510732694
3 676262960
1 770979443 -642438266
1 1...

output:

1705627

result:

ok single line: '1705627'