Submission #224136

# Submission time Handle Problem Language Result Execution time Memory
224136 2020-04-17T08:45:03 Z shenxy Fire (JOI20_ho_t5) C++11
14 / 100
1000 ms 40668 KB
#include <cstdio>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
using namespace std;
typedef pair<int, int> ii;
typedef pair<ii, ii> query;
struct seg {
    int s, e, m, v;
    seg *l, *r;
    seg(int _s, int _e) {
        s = _s, e = _e, m = (s + e) / 2, v = 0;
        if (s != e) {
            l = new seg(s, m);
            r = new seg(m + 1, e);
        }
    }
    void update(int i, int nv) {
        if (s != e) {
            if (i > m) r -> update(i, nv);
            else l -> update(i, nv);
            v = max(l -> v, r -> v);
        } else v = nv;
    }
    int query(int a, int b) {
        if (s == a && e == b) return v;
        if (a > m) return r -> query(a, b);
        if (b <= m) return l -> query(a, b);
        return max(l -> query(a, m), r -> query(m + 1, b));
    }
} *root;
struct Fenwick {
	int s;
	vector<long long> f;
	Fenwick(int N) {
		s = N;
		f = vector<long long>(s + 1);
	}
	void update(int i, long long v) {
		for (; i <= s; i += i & -i) f[i] += v;
	}
	long long query(int a) {
		long long ans = 0;
		for (; a > 0; a -= a & -a) ans += f[a];
		return ans;
	}
};
int main() {
	int N, Q;
	scanf("%d %d", &N, &Q);
	long long S[N];
	int T[Q], L[Q], R[Q];
	for (int i = 0; i < N; ++i) scanf("%lld", &S[i]);
	map<int, vector<int> > queries;
	for (int i = 0; i < Q; ++i) scanf("%d %d %d", &T[i], &L[i], &R[i]);
	for (int i = 0; i < Q; ++i) queries[T[i]].push_back(i);
	if (queries.size() == 1) {
		root = new seg(0, N - 1);
		for (int i = 0; i < N; ++i) root -> update(i, S[i]);
		for (int i = 0; i < N; ++i) S[i] = root -> query(max(0, i - queries.begin() -> first), i);
		for (int i = 1; i < N; ++i) S[i] += S[i - 1];
		for (int i = 0; i < Q; ++i) printf("%lld\n", S[R[i] - 1] - (L[i] == 1 ? 0 : S[L[i] - 2]));
	} else if (*max_element(S, S + N) <= 2) {
		int prev1 = -1, prev2 = -1;
		set<query> q;
		Fenwick f(N);
		for (int i = 0; i < N; ++i) f.update(i + 1, S[i]);
		long long ans[Q];
		for (int i = 0; i < N; ++i) {
			if (S[i] == 0) {
				if (prev2 != -1) q.insert(query(ii(i - prev2, -1), ii(2, i + 1)));
				else if (prev1 != -1) q.insert(query(ii(i - prev1, -1), ii(1, i + 1)));
			} else if (S[i] == 1) {
				if (prev2 != -1) q.insert(query(ii(i - prev2, -1), ii(1, i + 1)));
				prev1 = i;
			} else prev2 = i;
		}
		for (int i = 0; i < Q; ++i) q.insert(query(ii(T[i], i), ii(L[i], R[i])));
		for (query i: q) {
			if (i.first.second == -1) f.update(i.second.second, i.second.first);
			else ans[i.first.second] = f.query(i.second.second) - f.query(i.second.first - 1);
		}
		for (int i = 0; i < Q; ++i) printf("%lld\n", ans[Q]);
	} else {
		root = new seg(0, N - 1);
		for (int i = 0; i < N; ++i) root -> update(i, S[i]);
		for (int i = 0; i < Q; ++i) {
			long long ans = 0;
			for (int j = L[i] - 1; j < R[i]; ++j) ans += root -> query(max(0, j - T[i]), j);
			printf("%lld\n", ans);
		}
	}
	return 0;
}

Compilation message

ho_t5.cpp: In function 'int main()':
ho_t5.cpp:51:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &N, &Q);
  ~~~~~^~~~~~~~~~~~~~~~~
ho_t5.cpp:54:35: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for (int i = 0; i < N; ++i) scanf("%lld", &S[i]);
                              ~~~~~^~~~~~~~~~~~~~~
ho_t5.cpp:56:35: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for (int i = 0; i < Q; ++i) scanf("%d %d %d", &T[i], &L[i], &R[i]);
                              ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 6 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 6 ms 384 KB Output is correct
5 Correct 6 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 6 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 256 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 256 KB Output is correct
20 Correct 5 ms 256 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 256 KB Output is correct
23 Correct 6 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
27 Correct 5 ms 256 KB Output is correct
28 Correct 6 ms 384 KB Output is correct
29 Correct 5 ms 384 KB Output is correct
30 Correct 6 ms 256 KB Output is correct
31 Correct 5 ms 256 KB Output is correct
32 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 219 ms 26860 KB Output is correct
3 Correct 216 ms 26732 KB Output is correct
4 Correct 223 ms 26860 KB Output is correct
5 Correct 222 ms 27116 KB Output is correct
6 Correct 216 ms 26856 KB Output is correct
7 Correct 228 ms 27244 KB Output is correct
8 Correct 231 ms 27372 KB Output is correct
9 Correct 230 ms 27116 KB Output is correct
10 Correct 213 ms 26792 KB Output is correct
11 Correct 221 ms 27252 KB Output is correct
12 Correct 217 ms 26604 KB Output is correct
13 Correct 246 ms 27116 KB Output is correct
14 Correct 215 ms 27112 KB Output is correct
15 Correct 213 ms 27112 KB Output is correct
16 Correct 220 ms 26860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 465 ms 39544 KB Output is correct
3 Correct 427 ms 38520 KB Output is correct
4 Correct 447 ms 40184 KB Output is correct
5 Correct 430 ms 38732 KB Output is correct
6 Correct 437 ms 39200 KB Output is correct
7 Correct 432 ms 39416 KB Output is correct
8 Correct 435 ms 39344 KB Output is correct
9 Correct 448 ms 38956 KB Output is correct
10 Correct 437 ms 38392 KB Output is correct
11 Correct 454 ms 39928 KB Output is correct
12 Correct 429 ms 39288 KB Output is correct
13 Correct 435 ms 39800 KB Output is correct
14 Correct 432 ms 38904 KB Output is correct
15 Correct 438 ms 39672 KB Output is correct
16 Correct 427 ms 39144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 462 ms 40668 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 6 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 6 ms 384 KB Output is correct
5 Correct 6 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 6 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 256 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 256 KB Output is correct
20 Correct 5 ms 256 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 256 KB Output is correct
23 Correct 6 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
27 Correct 5 ms 256 KB Output is correct
28 Correct 6 ms 384 KB Output is correct
29 Correct 5 ms 384 KB Output is correct
30 Correct 6 ms 256 KB Output is correct
31 Correct 5 ms 256 KB Output is correct
32 Correct 5 ms 384 KB Output is correct
33 Execution timed out 1093 ms 36216 KB Time limit exceeded
34 Halted 0 ms 0 KB -