QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#196824 | #1964. Stock Price Prediction | Forever_Young# | WA | 527ms | 34772kb | C++14 | 3.0kb | 2023-10-01 23:55:15 | 2023-10-01 23:55:17 |
Judging History
answer
#include<bits/stdc++.h>
//#include<ext/pb_ds/tree_policy.hpp>
//#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
//typedef tree<pii, null, less<pii>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define fi first
#define se second
#define pb push_back
#define all(x) ((x).begin()), ((x).end())
const int N = 1000011;
int a[N], b[N];
int x[N], y[N], nxt[N];
int sgt[N * 4];
void build(int k, int le, int ri) {
sgt[k] = 0;
if(le < ri) {
int mid = (le + ri) / 2;
build(k * 2, le, mid);
build(k * 2 + 1, mid + 1, ri);
}
}
int getsum(int k, int le, int ri, int ql, int qr) {
if(ql <= le && ri <= qr) {
return sgt[k];
}else {
int mid = (le + ri) / 2;
int res = 0;
if(ql <= mid) res += getsum(k * 2, le, mid, ql, qr);
if(qr >= mid + 1) res += getsum(k * 2 + 1, mid + 1, ri, ql, qr);
return res;
}
}
void add(int k, int le, int ri, int pos, int delta) {
if(le == ri) {
sgt[k] += delta;
}else {
int mid = (le + ri) / 2;
if(pos <= mid) {
add(k * 2, le, mid, pos, delta);
}else {
add(k * 2 + 1, mid + 1, ri, pos, delta);
}
sgt[k] += delta;
}
}
void calc(int x[N], int a[N], int n) {
vector<pii> vec;
build(1, 1, n);
for(int i = 1; i <= n; i++) {
vec.pb({x[i], i});
}
sort(all(vec));
for(int i = 1; i <= n; i++) {
x[i] = lower_bound(all(vec), pii{x[i], i}) - vec.begin() + 1;
add(1, 1, n, x[i], 1);
a[i] = getsum(1, 1, n, 1, x[i]);
//printf("%d %d\n", x[i], a[i]);
}
}
bool cmp(pii a, pii b, int n) {
if(b.fi >= n) {
b.fi = -1;
}
if(b.se >= n) {
b.se = -1;
}
return a == b;
}
int main() {
int n, m;
scanf("%d%d", &n, &m);
for(int i = 1; i <= n; i++) {
scanf("%d", &x[i]);
}
for(int j = 1; j <= m; j++) {
scanf("%d", &y[j]);
}
calc(x, a, n);
calc(y, b, m);
nxt[0] = -1;
build(1, 1, n);
for(int i = 1; i <= n; i++) {
int p = nxt[i - 1];
if(i > 1) add(1, 1, n, x[i], 1);
while(p != -1 && a[p + 1] != getsum(1, 1, n, 1, x[i])) {
int q = nxt[p];
while(p > q) {
add(1, 1, n, x[i - p], -1);
p--;
}
}
nxt[i] = p + 1;
//printf("%d\n", nxt[i]);
}
int p = 0;
vector<int> ans;
build(1, 1, m);
for(int i = 1; i <= m; i++) {
add(1, 1, m, y[i], 1);
//cout << "+1" << ' ' << y[i] << endl;
while(p != -1 && a[p + 1] != getsum(1, 1, m, 1, y[i])) {
//cout << a[p + 1] << ' ' << getsum(1, 1, m, 1, y[i]) << endl;
int q = nxt[p];
while(p > q) {
//cout << "-1" << ' ' << y[i - p] << endl;
add(1, 1, m, y[i - p], -1);
p--;
}
}
p += 1;
//printf("%d\n", p);
if(p == n) {
ans.push_back(i - n + 1);
int q = nxt[p];
while(p > q) {
//cout << "-1" << ' ' << y[i - p] << endl;
add(1, 1, m, y[i - p + 1], -1);
p--;
}
}else {
}
}
if(ans.empty()) {
printf("-1\n");
exit(0);
}
for(int i = 0; i < (int)ans.size(); i++) {
printf("%d%c", ans[i], i == (int)ans.size() - 1 ? '\n' : ' ');
}
}
详细
Test #1:
score: 100
Accepted
time: 527ms
memory: 34772kb
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 ...997 989998 989999 990000 990001'
Test #2:
score: -100
Wrong Answer
time: 514ms
memory: 33188kb
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...002 950002 960002 970002 980002'