Submission #681612

# Submission time Handle Problem Language Result Execution time Memory
681612 2023-01-13T13:06:53 Z MilosMilutinovic Progression (NOI20_progression) C++14
0 / 100
394 ms 1048576 KB
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
#include <array>
using namespace std;

typedef long long ll;

const int N = 500500;
int n, q;
int d[N];

struct Node {
	int mx, len, L, R;
	ll lval, rval;

	Node() {}
};
Node const operator + (Node l, Node r) {
	Node res;
	res.lval = l.lval;
	res.rval = r.rval;
	res.L = l.L + (l.L == l.len && r.lval == l.rval ? r.L : 0);
	res.R = r.R + (r.R == r.len && l.rval == r.lval ? l.R : 0);
	res.mx = max({l.mx, r.mx, res.L, res.R});
	if (l.rval == r.lval)
		res.mx = max(res.mx, l.R + r.L);
	res.len = l.len + r.len;
	return res;
}
const int M = (1 << 23);
Node tree[M];
void build(int p, int l, int r) {
	if (l == r) {
		tree[p].lval = d[r + 1] - d[r];
		tree[p].rval = d[r + 1] - d[r];
		tree[p].mx = 1;
		tree[p].len = r - l + 1;
		tree[p].L = 1;
		tree[p].R = 1;
		return;
	}
	int mid = (l + r) / 2;
	build(p * 2, l, mid);
	build(p * 2 + 1, mid + 1, r);
	tree[p] = tree[p * 2] + tree[p * 2 + 1];
}
Node query(int p, int l, int r, int ql, int qr) {
	if (ql <= l && r <= qr) {
//		printf("SEG = [%d,%d]\n", l, r);
		return tree[p];
	}
	if (l > qr || r < ql || l > r || ql > qr) {
		exit(0);
	}
	int mid = (l + r) / 2;
	if (qr <= mid)
		return query(p * 2, l, mid, ql, qr);
	else if (ql >= mid + 1)
		return query(p * 2 + 1, mid + 1, r, ql, qr);
	else
		return query(p * 2, l, mid, ql, qr) + query(p * 2 + 1, mid + 1, r, ql, qr);
}

int main()
{
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	scanf("%d%d", &n, &q);
	for (int i = 1; i <= n; i++)
		scanf("%d", &d[i]);
	build(1, 1, n - 1);
	while(q--) {
		int op;
		scanf("%d", &op);
		if (op == 1) {

		} else if (op == 2) {
		} else {
			int l, r;
			scanf("%d%d", &l, &r);
			--r;
			if (l > r) {
				printf("%d\n", 1);
				continue;
			}
			printf("%d\n", query(1, 1, n - 1, l, r).mx + 1);
		}
	}
	return 0;
}

Compilation message

Progression.cpp: In function 'int main()':
Progression.cpp:86:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   86 |  scanf("%d%d", &n, &q);
      |  ~~~~~^~~~~~~~~~~~~~~~
Progression.cpp:88:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   88 |   scanf("%d", &d[i]);
      |   ~~~~~^~~~~~~~~~~~~
Progression.cpp:92:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   92 |   scanf("%d", &op);
      |   ~~~~~^~~~~~~~~~~
Progression.cpp:98:9: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   98 |    scanf("%d%d", &l, &r);
      |    ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 43 ms 34248 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 218 ms 35400 KB Output is correct
2 Correct 96 ms 844 KB Output is correct
3 Correct 96 ms 884 KB Output is correct
4 Correct 91 ms 888 KB Output is correct
5 Correct 98 ms 904 KB Output is correct
6 Correct 100 ms 944 KB Output is correct
7 Correct 99 ms 888 KB Output is correct
8 Runtime error 394 ms 1048576 KB Execution killed with signal 9
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 46 ms 34196 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 218 ms 35400 KB Output is correct
2 Correct 96 ms 844 KB Output is correct
3 Correct 96 ms 884 KB Output is correct
4 Correct 91 ms 888 KB Output is correct
5 Correct 98 ms 904 KB Output is correct
6 Correct 100 ms 944 KB Output is correct
7 Correct 99 ms 888 KB Output is correct
8 Runtime error 394 ms 1048576 KB Execution killed with signal 9
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 43 ms 34248 KB Output isn't correct
2 Halted 0 ms 0 KB -