Submission #838160

# Submission time Handle Problem Language Result Execution time Memory
838160 2023-08-26T09:47:55 Z mat_jur Secret (JOI14_secret) C++14
30 / 100
402 ms 4364 KB
#include <bits/stdc++.h>
#ifndef LOCAL 
#include "secret.h"
#else
int Secret(int x, int y) {return x+y;}
#endif
using namespace std;
#ifdef DEBUG
auto&operator<<(auto &o, pair<auto, auto> p) {o << "(" << p.first << ", " << p.second << ")"; return o;}
auto operator<<(auto &o, auto x)->decltype(x.end(), o) {o<<"{"; for(auto e : x) o<<e<<", "; return o<<"}";}
#define debug(X) cerr << "["#X"]: " << X << '\n';
#else 
#define debug(X) ;
#endif
#define ll long long
#define all(v) (v).begin(), (v).end()
#define FOR(i,l,r) for(int i=(l);i<=(r);++i)
#define REP(i,n) FOR(i,0,(n)-1)
#define ssize(x) int(x.size())
#define fi first
#define se second

class RMQ { //online
public:
	vector<vector<int>> st;
	int N, K;
	vector<int> lg;
	RMQ() {
		N = K = 0;
	}
	RMQ(vector<int> v) {
		N = v.size();
		st.resize(N);
		lg.resize(N+1);
		lg[1] = 0;
		FOR(i, 2, N) {
			lg[i] = lg[i/2]+1;
		}
		K = lg[N]+1;
		REP(i, N) st[i].resize(K);
		REP(j, K) {
			for (int i = 0; i+(1<<j)-1 < N; i++) {
				if (j == 0) {st[i][j] = v[i]; continue;}
				st[i][j] = Secret(st[i][j-1], st[i+(1<<(j-1))][j-1]);
			}
		}
	}
	void set(vector<int> v) {
		N = v.size();
		st.resize(N);
		lg.resize(N+1);
		lg[1] = 0;
		FOR(i, 2, N) {
			lg[i] = lg[i/2]+1;
		}
		K = lg[N]+1;
		REP(i, N) st[i].resize(K);
		REP(j, K) {
			for (int i = 0; i+(1<<j)-1 < N; i++) {
				if (j == 0) {st[i][j] = v[i]; continue;}
				st[i][j] = Secret(st[i][j-1], st[i+(1<<(j-1))][j-1]);
			}
		}
	}
	int query(int l, int r) {
		int res = st[l][0];
		l++;
		if (l > r) return res;
		int d = lg[r-l+1];
		while (l <= r) {
			if ((1<<d) <= r-l+1) {
				res = Secret(res, st[l][d]);
				l += (1<<d);
			}
			d--;
		}
		return res;
	}
};

RMQ st;
void Init(int N, int A[]) {
	vector<int> v(N);
	REP(i, N) v[i] = A[i];
	st.set(v);	
}

int Query(int L, int R) {
	return st.query(L, R);
}

#ifdef LOCAL
int main() {
	int n;
	cin >> n;
	int a[n];
	REP(i, n) cin >> a[i];
	Init(n, a);
	int q;
	cin >> q;
	while (q--) {
		int l, r;
		cin >> l >> r;
		cout << Query(l, r) << '\n';
	}

	return 0;
};
#endif
# Verdict Execution time Memory Grader output
1 Partially correct 128 ms 2376 KB Output is partially correct - number of calls to Secret by Init = 3586, maximum number of calls to Secret by Query = 8
2 Partially correct 126 ms 2380 KB Output is partially correct - number of calls to Secret by Init = 3595, maximum number of calls to Secret by Query = 8
3 Partially correct 122 ms 2332 KB Output is partially correct - number of calls to Secret by Init = 3604, maximum number of calls to Secret by Query = 8
4 Partially correct 386 ms 4320 KB Output is partially correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 9
5 Partially correct 382 ms 4332 KB Output is partially correct - number of calls to Secret by Init = 7987, maximum number of calls to Secret by Query = 9
6 Partially correct 362 ms 4324 KB Output is partially correct - number of calls to Secret by Init = 7987, maximum number of calls to Secret by Query = 3
7 Partially correct 402 ms 4364 KB Output is partially correct - number of calls to Secret by Init = 7987, maximum number of calls to Secret by Query = 9
8 Partially correct 395 ms 4360 KB Output is partially correct - number of calls to Secret by Init = 7987, maximum number of calls to Secret by Query = 9
9 Partially correct 388 ms 4356 KB Output is partially correct - number of calls to Secret by Init = 7987, maximum number of calls to Secret by Query = 8
10 Partially correct 397 ms 4264 KB Output is partially correct - number of calls to Secret by Init = 7987, maximum number of calls to Secret by Query = 9