# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
499847 | mars4 | Secret (JOI14_secret) | C++17 | 436 ms | 4548 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include "secret.h"
using namespace std;
using namespace __gnu_pbds;
#define ff first
#define ss second
#define ll int64_t
#define ld long double
#define nl cout<<"\n"
#define all(v) v.begin(),v.end()
#define mset(a,v) memset((a),(v),sizeof(a))
#define forn(i,a,b) for(int64_t i=int64_t(a);i<int64_t(b);++i)
#define forb(i,a,b) for(int64_t i=int64_t(a);i>=int64_t(b);--i)
#define fastio() ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mod 1'000'000'007
#define mod2 998'244'353
#define inf 1'000'000'000'000'007
#define pi 3.14159265358979323846
template<class key,class cmp=std::less<key>>
using ordered_set=tree<key,null_type,cmp,rb_tree_tag,tree_order_statistics_node_update>;
template<class L,class R> ostream& operator<<(ostream& out,pair<L,R> &p) {return out<<"("<<p.ff<<", "<<p.ss<<")";}
template<class T> ostream& operator<<(ostream& out,vector<T> &v) {out<<"[";for(auto it=v.begin();it!=v.end();++it){if(it!=v.begin())out<<", ";out<<*it;}return out<<"]";}
template<class T> ostream& operator<<(ostream& out,deque<T> &v) {out<<"[";for(auto it=v.begin();it!=v.end();++it){if(it!=v.begin())out<<", ";out<<*it;}return out<<"]";}
template<class T> ostream& operator<<(ostream& out,set<T> &s) {out<<"{";for(auto it=s.begin();it!=s.end();++it){if(it!=s.begin())out<<", ";out<<*it;}return out<<"}";}
template<class L,class R> ostream& operator<<(ostream& out,map<L,R> &m) {out<<"{";for(auto it=m.begin();it!=m.end();++it){if(it!=m.begin())out<<", ";out<<*it;}return out<<"}";}
void dbg_out() {cerr<<"]\n";}
template<typename Head,typename... Tail>
void dbg_out(Head H,Tail... T) {cerr<<H;if(sizeof...(Tail))cerr<<", ";dbg_out(T...);}
#ifdef LOCAL
#define dbg(...) cerr<<"["<<#__VA_ARGS__<<"] = [",dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif
//---------------------------------mars4---------------------------------
template<class T=int64_t> class DisjointSparse
{
ll N;
ll K;
vector<T> a;
T merge(T a,T b)
{
return Secret(a,b);
}
void build(ll l,ll r,ll level)
{
if(level<0)
{
return;
}
ll mid=(l+r)/2;
st[mid][level]=a[mid];
forb(i,mid-1,l)
{
if(i==N-1)
{
st[i][level]=a[i];
}
if(i<N-1)
{
st[i][level]=merge(a[i],st[i+1][level]);
}
}
st[mid+1][level]=a[mid+1];
forn(i,mid+2,r+1)
{
if(i<N)
{
st[i][level]=merge(st[i-1][level],a[i]);
}
}
build(l,mid,level-1);
build(mid+1,r,level-1);
}
public:
vector<vector<T>> st;
void init(vector<T> &a)
{
N=(ll)a.size();
this->a=a;
K=1;
while((1ll<<K)<N)
{
K++;
}
this->a.resize(1ll<<K);
st=vector<vector<T>>(1ll<<K,vector<T>(K));
build(0,(1ll<<K)-1,K-1);
}
T query(ll l,ll r)
{
if(l==r)
{
return a[l];
}
ll level=63-__builtin_clzll(l^r);
return merge(st[l][level],st[r][level]);
}
};
DisjointSparse<int> ds;
void Init(int N,int A[])
{
vector<int> a(N);
forn(i,0,N)
{
a[i]=A[i];
}
ds.init(a);
}
int Query(int L,int R)
{
return ds.query(L,R);
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |