QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#196835#1964. Stock Price PredictionForever_Young#WA 106ms19100kbC++141.7kb2023-10-02 00:27:002023-10-02 00:27:00

Judging History

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

  • [2023-10-02 00:27:00]
  • 评测
  • 测评结果:WA
  • 用时:106ms
  • 内存:19100kb
  • [2023-10-02 00:27:00]
  • 提交

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];

bool check(int p, int x[N], int i) {
	bool res = (a[p] == 0 || x[i] >= x[i - a[p]]) && (b[p] == 0 || x[i] <= x[i - b[p]]);
	//printf("%d %d %d\n", p, i, res);
	return res;
}
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]);
	}

	map<int, int> mp;
	for(int i = 1; i <= n; i++) {
		auto itr = mp.lower_bound(x[i]);
		
		if(itr != mp.end()) {
			b[i] = i - itr->se;
		}else {
			b[i] = 0;
		}

		itr = mp.upper_bound(x[i]);
		if(itr != mp.begin()) {
			itr--;
			a[i] = i - itr->se;
		}else {
			a[i] = 0;
		}
		mp[x[i]] = i;
		//printf("%d %d %d\n", i, a[i], b[i]);
	}
	nxt[0] = -1;
	for(int i = 1; i <= n; i++) {
		int p = nxt[i - 1];
		while(p != -1 && !check(p + 1, x, i)) {
			p = nxt[p];
		}
		nxt[i] = p + 1;
		//printf("nxt[%d] = %d\n", i, nxt[i]);
	}
	int p = 0;
	vector<int> ans;
	for(int i = 1; i <= m; i++) {
		while(p != -1 && !check(p + 1, y, i)) {
			p = nxt[p];
		}
		p += 1;
		if(p == n) {
			ans.push_back(i - n + 1);
			p = nxt[p];
		}else {
			
		}
	}
	if(ans.empty()) {
		printf("0\n");
		exit(0);
	}
	for(int i = 0; i < (int)ans.size(); i++) {
		printf("%d%c", ans[i], i == (int)ans.size() - 1 ? '\n' : ' ');
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 106ms
memory: 19100kb

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: 56ms
memory: 14540kb

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'