Submission #852516

# Submission time Handle Problem Language Result Execution time Memory
852516 2023-09-21T21:48:19 Z Ammar Secret (JOI14_secret) C++17
100 / 100
388 ms 4432 KB
#include <bits/stdc++.h>
#include "secret.h"
using namespace std;

int t[10][1001],msk[1001],b[1001];

void build(int x, int l, int r, int a[])
{
	if(l>=r)return;
	int mid=(l+r)/2;
	t[x][mid]=a[mid];
	for(int i=mid-1;i>=l;i--)
		t[x][i]=Secret(a[i],t[x][i+1]);
	
	t[x][mid+1]=a[mid+1];
	msk[mid+1]|=(1<<x);
	for(int i=mid+2;i<=r;i++)
	{
		t[x][i]=Secret(t[x][i-1],a[i]);
		msk[i]|=(1<<x);
	}
	build(x+1,l,mid,a);
	build(x+1,mid+1,r,a);
}

void Init(int n, int a[])
{
	for(int i=0;i<n;i++)b[i]=a[i];
	build(0,0,n-1,a);
}

int Query(int l, int r)
{
	if(l==r)return b[l];
	int z=__builtin_ctz(msk[l]^msk[r]);
	return Secret(t[z][l],t[z][r]);
}
# Verdict Execution time Memory Grader output
1 Correct 106 ms 2648 KB Output is correct - number of calls to Secret by Init = 3578, maximum number of calls to Secret by Query = 1
2 Correct 108 ms 2652 KB Output is correct - number of calls to Secret by Init = 3586, maximum number of calls to Secret by Query = 1
3 Correct 110 ms 2648 KB Output is correct - number of calls to Secret by Init = 3595, maximum number of calls to Secret by Query = 1
4 Correct 384 ms 4432 KB Output is correct - number of calls to Secret by Init = 7969, maximum number of calls to Secret by Query = 1
5 Correct 377 ms 4432 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
6 Correct 376 ms 4432 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
7 Correct 381 ms 4420 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
8 Correct 383 ms 4256 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
9 Correct 388 ms 4432 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
10 Correct 387 ms 4432 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1