QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#617530 | #1964. Stock Price Prediction | untitledtwo# | WA | 453ms | 386284kb | C++17 | 2.2kb | 2024-10-06 16:02:50 | 2024-10-06 16:02:51 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1000005;
const int INF = 0x3f3f3f3f;
const int MX = (int)1e9;
#define fi first
#define se second
#define MP make_pair
#define PB push_back
int sum[MAXN << 1], s[MAXN * 40], ls[MAXN * 40], rs[MAXN * 40], rt[MAXN], rnk[MAXN], c[MAXN], nxt[MAXN], nodenum = 0, n, m, Num = 0;
int a[MAXN], b[MAXN];
map<int, int> Map;
int query(int x) {
int ans = 0;
for (; x ; x -= x & (-x)) ans += sum[x];
return ans;
}
void add(int x, int y) {
for (; x <= Num ; x += x & (-x)) sum[x] += y;
}
int Insert(int x, int l, int r, int y) {
int z = ++ nodenum;
s[z] = s[x] + 1, ls[z] = ls[x], rs[z] = rs[x];
if (l == r) return z;
int mid = (l + r) >> 1;
if (y <= mid) ls[z] = Insert(ls[z], l, mid, y);
else rs[z] = Insert(rs[z], mid + 1, r, y);
return z;
}
int query(int x, int l, int r, int y) {
if (!x) return 0;
if (r <= y) return s[x];
int mid = (l + r) >> 1;
if (y < mid) return query(ls[x], l, mid, y);
return s[ls[x]] + query(rs[x], mid + 1, r, y);
}
int getrnk(int l, int r, int y) {
return query(rt[r], 1, MX, y) - query(rt[l - 1], 1, MX, y);
}
signed main() {
#ifndef ONLINE_JUDGE
freopen("a.in", "r", stdin);
#endif
scanf("%d%d", &n, &m);
for (int i = 1; i <= n ; ++ i) scanf("%d", &a[i]), c[i] = a[i];
for (int i = 1; i <= m ; ++ i) scanf("%d", &b[i]);
sort(c + 1, c + n + 1);
for (int i = 1; i <= n ; ++ i)
if (Map.find(c[i]) == Map.end()) Map[c[i]] = ++ Num;
for (int i = 1; i <= n ; ++ i) add(Map[a[i]], 1), rnk[i] = query(Map[a[i]]);
for (int i = 1; i <= n ; ++ i) rt[i] = Insert(rt[i - 1], 1, MX, a[i]);
for (int i = 2, j = 0; i <= n ; ++ i) {
while (j && getrnk(i - j, i, a[i]) != rnk[j + 1]) j = nxt[j];
if (getrnk(i - j, i, a[i]) == rnk[j + 1]) ++ j;
nxt[i] = j;
}
for (int i = 1; i <= nodenum ; ++ i) s[i] = ls[i] = rs[i] = 0;
nodenum = 0;
for (int i = 1; i <= m ; ++ i) rt[i] = Insert(rt[i - 1], 1, MX, b[i]);
int flag = 0;
for (int i = 1, j = 0; i <= m ; ++ i) {
while (j && getrnk(i - j, i, b[i]) != rnk[j + 1]) j = nxt[j];
if (getrnk(i - j, i, b[i]) == rnk[j + 1]) ++ j;
if (j == n) { printf("%d ", i - n + 1), flag = 1, j = nxt[j]; }
}
if (!flag) puts("0");
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 453ms
memory: 386284kb
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: 420ms
memory: 383308kb
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 '