QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#340005#1964. Stock Price Predictionucup-team1209#WA 194ms37608kbC++202.8kb2024-02-28 11:48:322024-02-28 11:48:33

Judging History

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

  • [2024-02-28 11:48:33]
  • 评测
  • 测评结果:WA
  • 用时:194ms
  • 内存:37608kb
  • [2024-02-28 11:48:32]
  • 提交

answer

#include <bits/stdc++.h>
#define cs const
#define pb push_back
using namespace std;

cs int N = 2e6; 

int n, m; 
int a[N], b[N];
int aa[N], bb[N]; 
int nxt[N];

int c0[N], c1[N], T; 
void add(int x, int c) {
    for(; x <= T; x += x & -x) c0[x] += c;
} 
int rk(int x) {
    int ans = 0; 
    for(; x; x -= x & -x) ans += c0[x];
    return ans; 
} 
void addb(int x, int c) {
    for(; x <= T; x += x & -x) c1[x] += c; 
} 
int rkb(int x) {
    int ans = 0; 
    for(; x; x -= x & -x) ans += c1[x];
    return ans; 
}

int main() {
    #ifdef zqj
    freopen("1.in","r",stdin);
    #endif
    ios :: sync_with_stdio(0), cin.tie(0);
    cin >> n >> m; 

    for(int i = 1; i <= n; i++) cin >> a[i], aa[i] = a[i];
    for(int i =1 ; i <= m; i++) cin >> b[i], bb[i] = b[i];
    sort(aa + 1, aa + n + 1); 
    sort(bb + 1, bb + m + 1);
    int cc = unique(aa + 1, aa + n + 1) - aa - 1; 
    int dd = unique(bb + 1, bb + m + 1) - bb - 1; 
    T = max(cc, dd);
    for(int i = 1; i  <= n; i++) a[i] = lower_bound(aa + 1, aa + cc + 1, a[i]) - aa; 
    for(int i = 1; i  <= m; i++) b[i] = lower_bound(bb + 1, bb + dd + 1, b[i]) - bb; 
    for(int i = 2, j = 0; i <= n; i++) {
        // rank a[i] in [i - j, i - 1]
        // rank a[j + 1] in [1, j]
        while(j && rkb(a[i]) != rk(a[j + 1])) {
            int k = nxt[j];
            while(j > k) {
                add(a[j], -1);
                addb(a[i - j], -1);
                -- j; 
            }
        }
        if(rkb(a[i]) == rk(a[j + 1])) ++ j, add(a[j], 1);
        nxt[i] = j;
        addb(a[i], 1);
        // cout << i << ' ' << nxt[i] << endl;
    }
    memset(c0, 0, sizeof c0);
    memset(c1, 0, sizeof c1);
    int flag = 0; 
    for(int i = 1, j = 0; i <= m; i++) {
        // rank b[i] in [i - j, i - 1]
        // rank a[j + 1] in [1, j]
        while(j && rkb(b[i]) != rk(a[j + 1])) {
            int k = nxt[j];
            while(j > k) {
                add(a[j], -1);
                // cerr << "decffs " << i - j << endl;
                addb(b[i - j], -1);
                -- j; 
            }
        }
        // cout << i << ' ' << j << ' ' << rk(a[j + 1]) << ' ' <<rkb(b[i]) << endl;
        if(rk(a[j + 1]) == rkb(b[i])) {
            ++ j;
            add(a[j], 1);
        }
        // cout << i << ' ' << j << endl;
        // cerr << "add " << i << endl;
        addb(b[i], 1);
        if(j == n) {
            flag =1; 
            cout << i - j + 1 << ' ';
            int k = nxt[j];
            while(j > k) {
                add(a[j], -1);
                addb(b[i - j + 1], -1);
                // cerr << "dec " << i - j << endl;
                -- j; 
            }
        }
    }
    if(flag == 0) {
        cout << 0 << '\n';
    }
    else {
        cout << '\n';
    }
    return 0; 
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 194ms
memory: 37136kb

input:

10000 1000000
1 2 3 4 5 6 7 8 9 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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 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 9...

output:

1 2 3 4 5 6 7 8 9 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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 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 ...

result:

ok single line: '1 2 3 4 5 6 7 8 9 10 11 12 13 ...97 989998 989999 990000 990001 '

Test #2:

score: -100
Wrong Answer
time: 178ms
memory: 37608kb

input:

10000 1000000
1 2 3 4 5 6 7 8 9 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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 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 9...

output:

1 2 10002 20002 30002 40002 50002 60002 70002 80002 90002 100002 110002 120002 130002 140002 150002 160002 170002 180002 190002 200002 210002 220002 230002 240002 250002 260002 270002 280002 290002 300002 310002 320002 330002 340002 350002 360002 370002 380002 390002 400002 410002 420002 430002 4400...

result:

wrong answer 1st lines differ - expected: '2 10002 20002 30002 40002 5000...002 950002 960002 970002 980002', found: '1 2 10002 20002 30002 40002 50...02 950002 960002 970002 980002 '