Submission #314456

# Submission time Handle Problem Language Result Execution time Memory
314456 2020-10-20T01:04:05 Z jc713 Secret (JOI14_secret) C++17
0 / 100
503 ms 8860 KB
#include "secret.h"

#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using ld = long double;
using db = double;
using str = string; // yay python!

using pi = pair<int,int>;
using pl = pair<ll,ll>;
using pd = pair<db,db>;

using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<ll>;
using vd = vector<db>;
using vs = vector<str>;
using vpi = vector<pi>;
using vpl = vector<pl>;
using vpd = vector<pd>;

#define tcT template<class T
// ^ lol this makes everything look weird but I'll try it
tcT> using V = vector<T>;
tcT, size_t SZ> using AR = array<T,SZ>;

// pairs
#define mp make_pair
#define f first
#define s second

// vectors
#define sz(x) (int)(x).size()
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define sor(x) sort(all(x))
#define rsz resize
#define ins insert
#define ft front()
#define bk back()
#define pf push_front
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound

// loops
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)

const int MOD = 1e9+7; // 998244353;
const int MX = 2e5+5;
const ll INF = 1e18; // not too close to LLONG_MAX
const ld PI = acos((ld)-1);
const int xd[4] = {1,0,-1,0}, yd[4] = {0,1,0,-1}; // for every grid problem!!
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());

// helper funcs
constexpr int pct(int x) { return __builtin_popcount(x); } // # of bits set
constexpr int bits(int x) { return 31-__builtin_clz(x); } // floor(log2(x))
ll cdiv(ll a, ll b) { return a/b+((a^b)>0&&a%b); } // divide a by b rounded up
ll fdiv(ll a, ll b) { return a/b-((a^b)<0&&a%b); } // divide a by b rounded down

template<class T, int SZ> struct RangeQuery {
	int n; int orig;
	T stor[SZ][32-__builtin_clz(SZ)], id = -1;
	vector<T> a;
	T comb (T a, T b) { return Secret(a,b); } // associative operation
	void fill(int l, int r, int ind) {
		if (ind < 0) return;
		int m = (l+r)/2;
		T prod = id; ROF(i,l,m){
			if(prod == id)
				stor[i][ind] = prod = a[i];
			else
				stor[i][ind] = prod = comb(a[i],prod);
		}
		prod = id; FOR(i,m,min(r, orig)){
			if(prod == id)
				stor[i][ind] = prod = a[i];
			else
				stor[i][ind] = prod = comb(prod,a[i]);
		}
		fill(l,m,ind-1); fill(m,r,ind-1);
	}
	void init() {
		n = 1; while ((1<<n) < sz(a)) n ++;
		a.rsz(1<<n); fill(0,(1<<n),n-1);
	}
	T query(int l, int r) {
		if (l == r) return a[l];
		int t = 31-__builtin_clz(r^l);
		return comb(stor[l][t],stor[r][t]);
	}
};

RangeQuery<int, 1000> RQ;

void Init(int N, int A[]) {
	RQ.orig = N;
	F0R(i, N)
		RQ.a[i] = A[i];
	RQ.init();
}

int Query(int L, int R) {
  	return RQ.query(L, R);
}
# Verdict Execution time Memory Grader output
1 Runtime error 133 ms 4960 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Runtime error 134 ms 4856 KB Execution killed with signal 11 (could be triggered by violating memory limits)
3 Runtime error 135 ms 4856 KB Execution killed with signal 11 (could be triggered by violating memory limits)
4 Runtime error 492 ms 8860 KB Execution killed with signal 11 (could be triggered by violating memory limits)
5 Runtime error 488 ms 8824 KB Execution killed with signal 11 (could be triggered by violating memory limits)
6 Runtime error 498 ms 8700 KB Execution killed with signal 11 (could be triggered by violating memory limits)
7 Runtime error 494 ms 8824 KB Execution killed with signal 11 (could be triggered by violating memory limits)
8 Runtime error 503 ms 8612 KB Execution killed with signal 11 (could be triggered by violating memory limits)
9 Runtime error 493 ms 8824 KB Execution killed with signal 11 (could be triggered by violating memory limits)
10 Runtime error 495 ms 8728 KB Execution killed with signal 11 (could be triggered by violating memory limits)