답안 #1092751

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1092751 2024-09-25T00:01:16 Z Saul0906 비밀 (JOI14_secret) C++14
100 / 100
317 ms 4752 KB
#include "secret.h"
#include <bits/stdc++.h>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fi first
#define se second
#define endl "\n"
#define rep(a,b,c) for(ll a=b; a<c; a++)
#define rep2(a,b,c,d) for(ll a=b; a<c; a+=d)
#define repr(a,b,c) for(ll a=b-1; a>c-1; a--)
#define repa(a,b) for(const auto &a: b)
#define multicase() int t; cin>>t; while(t--)
#define fastIO() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define valid(c) cout<<(c ? "YES" : "NO")<<endl;
#define valid2(c,a,b) cout<<(c ? a : b)<<endl;
#define ll long long 
#define pq_min(a) priority_queue<a, vector<a>, greater<a>>
#define pq_max(a) priority_queue<a>
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define mid ((l+r)>>1)
#define flush endl<<flush
#define vi vector<int>

using namespace std;

int n;
vi a;

struct segtree{
	segtree *left, *right;
	int l, r;
	vi p, s;
	segtree(){}
	segtree(int x, int y): l(x), r(y){
		if(l==r){
			p.pb(a[l]);
			s.pb(a[l]);
			return;
		}
		left = new segtree(l,mid);
		right = new segtree(mid+1,r);
		if(x==0 && y==n-1) return;
		p.resize(r-l+1);
		s.resize(r-l+1);
		p[0]=left->p[0];
		s[0]=Secret(left->p.back(),right->p.back());
		s[r-l]=right->s.back();
		p[r-l]=s[0];
		rep(i,l+1,r){
			if(i>mid){
				p[i-l]=Secret(left->p.back(),right->p[i-mid-1]);
				s[i-l]=right->s[i-mid-1];
				
			}else{
				p[i-l]=left->p[i-l];
				s[i-l]=Secret(left->s[i-l],right->p.back());
			}
		}
	}
	int query(int x, int y){
		if(x==y) return a[x];
		if(y<l || r<x) return 0;
		if(x<=mid && y>mid){
			return Secret(left->s[x-l],right->p[y-mid-1]);
		}
		return left->query(x,y)+right->query(x,y);
	}
} st;

void Init(int N, int A[]) {
	a.resize(N);
	n=N;
	rep(i,0,n) a[i]=A[i];
	st = segtree(0,N-1);
}

int Query(int L, int R) {
	return st.query(L,R);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 86 ms 2644 KB Output is correct - number of calls to Secret by Init = 3578, maximum number of calls to Secret by Query = 1
2 Correct 89 ms 2604 KB Output is correct - number of calls to Secret by Init = 3586, maximum number of calls to Secret by Query = 1
3 Correct 85 ms 2644 KB Output is correct - number of calls to Secret by Init = 3595, maximum number of calls to Secret by Query = 1
4 Correct 317 ms 4696 KB Output is correct - number of calls to Secret by Init = 7969, maximum number of calls to Secret by Query = 1
5 Correct 306 ms 4672 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
6 Correct 314 ms 4692 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
7 Correct 306 ms 4692 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
8 Correct 304 ms 4752 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
9 Correct 308 ms 4692 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1
10 Correct 314 ms 4716 KB Output is correct - number of calls to Secret by Init = 7978, maximum number of calls to Secret by Query = 1