QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#67291#5098. 第一代图灵机Scapegoat_Dawn0 492ms41912kbC++143.2kb2022-12-10 11:30:272022-12-10 11:30:28

Judging History

This is the latest submission verdict.

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-12-10 11:30:28]
  • Judged
  • Verdict: 0
  • Time: 492ms
  • Memory: 41912kb
  • [2022-12-10 11:30:27]
  • Submitted

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;
inline int read() {
    int x = 0;
    char c = getchar();
    bool f = 0;
    while(!isdigit(c)) f |= (c == '-'), c = getchar();
    while(isdigit(c)) x = (x * 10) + (c ^ 48), c = getchar();
    return f ? -x : x;
}
const int maxn = 2 * 1e5 + 5, INF = 1e18 + 7;
int n, m, Q;
int a[maxn], c[maxn], Sum[maxn], Nex[maxn];
set <int> Col[maxn];
struct node {
    int Ans, LAns, MinNex;
}Tree[maxn << 2];
#define lc(i) i << 1
#define rc(i) i << 1 | 1
inline int Push_Up2(int i, int l, int r, int RMin) {
    if(l == r) { 
        RMin = min(RMin, Tree[i].MinNex);
        return Sum[RMin] - Sum[l]; 
    }
    int mid = (l + r) >> 1, rmin = Tree[rc(i)].MinNex;
    if(RMin <= rmin) return max(Sum[RMin] - Sum[mid + 1], Push_Up2(lc(i), l, mid, RMin));
    else return max(Tree[i].LAns, Push_Up2(rc(i), mid + 1, r, RMin));
}
inline void Push_Up(int i, int l, int r) {
    int mid = (l + r) >> 1;  
    Tree[i].MinNex = min(Tree[lc(i)].MinNex, Tree[rc(i)].MinNex);
    Tree[i].LAns = Push_Up2(lc(i), l, mid, Tree[rc(i)].MinNex);
    Tree[i].Ans = max(Tree[i].LAns, Tree[rc(i)].Ans);
}
inline void Update(int i, int l, int r, int x, int num) {
    if(l == r) { Tree[i].MinNex = num, Tree[i].Ans = Sum[num] - Sum[l]; return ; }
    int mid = (l + r) >> 1;
    if(x <= mid) Update(lc(i), l, mid, x, num);
    else Update(rc(i), mid + 1, r, x, num);
    Push_Up(i, l, r);
}
inline int Query2(int i, int l, int r, int RMin) {
    if(l == r) { 
        RMin = min(RMin, Tree[i].MinNex);
        return Sum[RMin] - Sum[l]; 
    }
    int mid = (l + r) >> 1, rmin = Tree[rc(i)].MinNex;
    if(RMin <= rmin) return max(Sum[RMin] - Sum[mid + 1], Query2(lc(i), l, mid, RMin));
    else return max(Tree[i].LAns, Query2(rc(i), mid + 1, r, RMin));
}
int RMin;
inline int Query(int i, int l, int r, int ql, int qr) {
    if(l >= ql && r <= qr) { 
        int mid = (l + r) >> 1, Ans = Query2(i, l, r, RMin);
        RMin = min(RMin, Tree[i].MinNex);
        return Ans;
    }
    int mid = (l + r) >> 1, Ans = 0;
    if(qr > mid) Ans = max(Ans, Query(rc(i), mid + 1, r, ql, qr));
    if(ql <= mid) Ans = max(Ans, Query(lc(i), l, mid, ql, qr));
    return Ans;
}
inline void Delet(int i) {
    auto pos = Col[c[i]].lower_bound(i), pre = pos, nex = pos;
    ++nex, --pre;
    Nex[*pre] = *nex;
    Col[c[i]].erase(pos);
}
inline void Insert(int i, int col) {
    auto pos = Col[col].lower_bound(i), pre = pos, nex = pos;
    --pre;
    Nex[*pre] = i, Nex[i] = *nex;
    Col[col].emplace(i);
}
signed main() {
    n = read(), m = read(), Q = read();
    for(register int i = 1; i <= n; ++i) a[i] = read(), Sum[i] = Sum[i - 1] + a[i];
    for(register int i = 1; i <= m; ++i) Col[i].emplace(n + 1);
    for(register int i = 1; i <= n; ++i) c[i] = read();
    for(register int i = n; i >= 1; --i) {
        int pos = *Col[c[i]].lower_bound(i);
        Nex[i] = pos, Col[c[i]].emplace(i), Update(1, 1, n, i, Nex[i]);
//        printf("%d %d\n", i, Nex[i]);
    }
    while(Q--) {
        int op = read(), l = read(), r = read(); RMin = r + 1;
        if(op == 1) printf("%lld\n", Query(1, 1, n, l, r));
        else Delet(l), Insert(l, r), Update(1, 1, n, l, Nex[l]);
    }
    return 0;
}

详细

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 7ms
memory: 13660kb

input:

5000 200 5000
2315 3433 1793 4621 4627 4561 289 4399 3822 2392 392 4581 2643 2441 4572 4649 2981 3094 4206 2057 761 2516 2849 3509 3033 658 4965 3316 3269 4284 4961 753 1187 2515 1377 1725 4743 4761 3823 3464 4859 989 2401 953 875 1481 2181 103 2067 2625 3296 4721 61 3843 1607 997 4385 1284 4299 441...

output:

118147
91657
81462
95036
95036
92537
72960
99929
99929
99929
99929
91657
99929
99929
91657
118147
92537
95036
58613
118147
99929
99929
99929
38174
88925
118147
98182
99929
99929
95080
84991
99929
118147
99929
99929
99929
99929
99929
99929
27385
99929
98182
99929
118147
99929
99929
98182
99929
58744
...

result:

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

Subtask #2:

score: 0
Wrong Answer

Test #3:

score: 0
Wrong Answer
time: 492ms
memory: 40788kb

input:

200000 10 200000
55651 97298 108697 86619 60721 199951 10610 162267 154301 138848 39191 18605 101369 57073 34977 101576 71252 143401 89587 160521 166491 38442 150761 35579 25571 121311 38033 38483 144639 41401 179161 54872 157905 137601 46863 187656 171901 43715 41036 150741 69057 102031 130561 4772...

output:

1242764
1171094
1241500
1242764
1242764
1242764
1242764
1242764
1241500
1242764
983057
1179750
1241500
1242764
1242764
1242764
1242764
1137431
1242764
1242764
1241500
1179750
1225404
1227971
1242764
1179750
1242764
1179750
1182670
1182670
1087432
1242764
1242764
1182670
1182670
1242764
1171094
11797...

result:

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

Subtask #3:

score: 0
Wrong Answer

Test #5:

score: 0
Wrong Answer
time: 473ms
memory: 41912kb

input:

200000 20000 200000
30681 32496 35471 48191 159123 69792 120915 150673 187226 158493 36275 26856 107976 124777 145229 69745 183961 14497 144808 153612 185893 137681 66417 46802 19345 113322 168046 128149 191001 135433 13201 139214 59489 81178 42343 163158 110121 119201 97501 53079 158755 192241 1132...

output:

46663174
46663174
38392860
38551256
38551256
42937757
39052426
46663174
46663174
46663174
27436102
38446268
46663174
46663174
42937757
42363930
39052426
42363930
46663174
46663174
46663174
41849077
46663174
34041414
46663174
38551256
46663174
28721187
46663174
42937757
42937757
38086897
46663174
466...

result:

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

Subtask #4:

score: 0
Skipped

Dependency #1:

0%

Subtask #5:

score: 0
Skipped

Dependency #4:

0%