Submission #656742

# Submission time Handle Problem Language Result Execution time Memory
656742 2022-11-08T06:59:15 Z anhduc2701 Secret (JOI14_secret) C++17
100 / 100
502 ms 12148 KB
#include<bits/stdc++.h>
#include "secret.h"
using namespace std;
typedef long long ll;
const ll INF=1e18;
const int maxn=1e6+5;
const int mod=1e9+7;
const int mo=998244353;
using pi=pair<ll,ll>;
using vi=vector<ll>;
using pii=pair<pair<ll,ll>,ll>;
#define all(x) x.begin(), x.end()
#define len(x) ll(x.size())
#define eb emplace_back
#define PI 3.14159265359
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define MIN(v) *min_element(all(v))
#define MAX(v) *max_element(all(v))
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int pre[1005][1005];
int suf[1005][1005];
int n;
int a[1005];
/*
int Secret(int x,int y){
    cout<<x<<" "<<y<<"\n";
    int k;
    cin>>k;
    return k;
}
*/
void bu1(int l,int r){
	if(r-l+1>=2){
		int mid=(l+r)/2;
		pre[mid+1][mid+1]=a[mid+1];
		for(int i=mid+2;i<=r;i++){
			pre[mid+1][i]=Secret(pre[mid+1][i-1],a[i]);
		}
		suf[mid][mid]=a[mid];
		for(int i=mid-1;i>=l;i--){
			suf[mid][i]=Secret(a[i],suf[mid][i+1]);
		}
	}
}
void build(int id,int l,int r){
	if(l==r){
		pre[l][l]=a[l];
		suf[l][l]=a[r];
		return;
	}
	int mid=(l+r)/2;
	bu1(l,r);
	build(id*2,l,mid);
	build(id*2+1,mid+1,r);
}
int que(int id,int l,int r,int u,int v){
	int mid=(l+r)/2;
	if(u<=mid && v>mid){
		return Secret(suf[mid][u],pre[mid+1][v]);
	}
	else if( v<=mid){
		return que(id*2,l,mid,u,v);
	}
	else{
		return que(id*2+1,mid+1,r,u,v);
	}
}
int Query(int l,int r){
    l++;
    r++;
    if(l==r)return a[l];
    else if(l==r-1)return Secret(a[l],a[r]);
    else return que(1,1,n,l,r);
}
void Init(int N,int A[]){
    n=N;
    for(int i=1;i<=N;i++){
        a[i]=A[i-1];
    }
	build(1,1,N);
}
# Verdict Execution time Memory Grader output
1 Correct 123 ms 6408 KB Output is correct - number of calls to Secret by Init = 3578, maximum number of calls to Secret by Query = 1
2 Correct 141 ms 6420 KB Output is correct - number of calls to Secret by Init = 3586, maximum number of calls to Secret by Query = 1
3 Correct 128 ms 6428 KB Output is correct - number of calls to Secret by Init = 3595, maximum number of calls to Secret by Query = 1
4 Correct 448 ms 12112 KB Output is correct - number of calls to Secret by Init = 7969, maximum number of calls to Secret by Query = 1
5 Correct 432 ms 12100 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
6 Correct 502 ms 12108 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
7 Correct 438 ms 12096 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
8 Correct 431 ms 12052 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
9 Correct 441 ms 12148 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
10 Correct 433 ms 12100 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1