답안 #477539

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
477539 2021-10-02T13:43:19 Z NhatMinh0208 3단 점프 (JOI19_jumps) C++14
0 / 100
48 ms 49844 KB
#ifndef CPL_TEMPLATE
#define CPL_TEMPLATE
/*
	Normie's Template v2.5
	Changes:
    Added warning against using pragmas on USACO.
*/
// Standard library in one include.
#include <bits/stdc++.h>
using namespace std;
 
// ordered_set library.
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set(el) tree<el,nuint_type,less<el>,rb_tree_tag,tree_order_statistics_node_update>
 
// AtCoder library. (Comment out these two lines if you're not submitting in AtCoder.) (Or if you want to use it in other judges, run expander.py first.)
//#include <atcoder/all>
//using namespace atcoder;

//Pragmas (Comment out these three lines if you're submitting in szkopul or USACO.)
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast,unroll-loops,tree-vectorize")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
 
//File I/O.
#define FILE_IN "cseq.inp"
#define FILE_OUT "cseq.out"
#define ofile freopen(FILE_IN,"r",stdin);freopen(FILE_OUT,"w",stdout)
 
//Fast I/O.
#define fio ios::sync_with_stdio(0);cin.tie(0)
#define nfio cin.tie(0)
#define endl "\n"
 
//Order checking.
#define ord(a,b,c) ((a>=b)and(b>=c))
 
//min/max redefines, so i dont have to resolve annoying compile errors.
#define min(a,b) (((a)<(b))?(a):(b))
#define max(a,b) (((a)>(b))?(a):(b))

// Fast min/max assigns to use with AVX.
// Requires g++ 9.2.0.
template<typename T>
__attribute__((always_inline)) void chkmin(T& a, const T& b) {
    a=(a<b)?a:b;
}

template<typename T>
__attribute__((always_inline)) void chkmax(T& a, const T& b) {
    a=(a>b)?a:b;
}
 
//Constants.
#define MOD (ll(998244353))
#define MAX 300001
#define mag 320
const long double PI=3.14159265358979;
 
//Pairs and 3-pairs.
#define p1 first
#define p2 second.first
#define p3 second.second
#define fi first
#define se second
#define pii(element_type) pair<element_type,element_type>
#define piii(element_type) pair<element_type,pii(element_type)>
 
//Quick power of 2.
#define pow2(x) (ll(1)<<x)
 
//Short for-loops.
#define ff(i,__,___) for(int i=__;i<=___;i++)
#define rr(i,__,___) for(int i=__;i>=___;i--)
 
//Typedefs.
#define bi BigInt
typedef long long ll;
typedef long double ld;
typedef short sh;

// Binpow and stuff
ll BOW(ll a, ll x, ll p)
{
	if (!x) return 1;
	ll res=BOW(a,x/2,p);
	res*=res;
	res%=p;
	if (x%2) res*=a;
	return res%p;
}
ll INV(ll a, ll p)
{
	return BOW(a,p-2,p);
}
//---------END-------//
#endif
struct seg1 {
	int val[1100001];
	int vl[1100001];
	int vr[1100001];
	void reset(int c, int l, int r) {
		val[c]=-1e9;
		vl[c]=l;
		vr[c]=r;
		if (l<r) {
			int mid=(l+r)/2;
			reset((c<<1),l,mid);
			reset((c<<1)+1,mid+1,r);
		}
	}
	void upd(int c, int l, int r, int tl, int tr, int x) {
		if (l>tr || r<tl) return;
		if (l>=tl && r<=tr) {
			val[c]=x;
			vl[c]=l;
			vr[c]=r;
			return;
		}
		int mid=(l+r)/2;
		upd((c<<1),l,mid,tl,tr,x);
		upd((c<<1)+1,mid+1,r,tl,tr,x);
		if (val[(c<<1)]<val[(c<<1)+1]) {
			val[c]=val[(c<<1)];
			vl[c]=vl[(c<<1)];
			vr[c]=vr[(c<<1)];
		} else if (val[(c<<1)]>val[(c<<1)+1]) {
			val[c]=val[(c<<1)+1];
			vl[c]=vl[(c<<1)+1];
			vr[c]=vr[(c<<1)+1];
		} else {
			val[c]=val[(c<<1)+1];
			vl[c]=vl[(c<<1)];
			vr[c]=vr[(c<<1)+1];
		}
	}
	piii(int) get(int c, int l, int r, int tl, int tr) {
		if (l>tr || r<tl) return {1e9,{l,r}};
		if (l>=tl && r<=tr) {
			return {val[c],{vl[c],vr[c]}};
		}
		int mid=(l+r)/2;
		auto a = get((c<<1),l,mid,tl,tr);
		auto b = get((c<<1)+1,mid+1,r,tl,tr);
		if (a.p1>b.p1) {
			return b;
		} else if (a.p1<b.p1) {
			return a;
		} else {
			return {a.p1,{a.p2,b.p3}};
		}
	}
};
seg1 st1;

int star[500001];
struct seg
{
	int val[1100401],lazy[1100401];
	vector<piii(int)> nodes;
	int n;
	void resetK(int l, int r, int cur)
	{
		if (l==r)
		{
			lazy[cur]=0;
			val[cur]=star[l];
		}
		else
		{
			lazy[cur]=0;
			int mid=(l+r)/2;
			resetK(l,mid,(cur<<1));
			resetK(mid+1,r,(cur<<1)+1);
			val[cur]=max(val[(cur<<1)],val[(cur<<1)+1]);
		}
	}
	void reset(int nn)
	{
		n=nn;
		resetK(1,n,1);
	}
	void flusha(int cur)
	{
	//	cout<<"flusha "<<cur<<endl;
	//	cout<<"before: "<<lazy[(cur<<1)]<<' '<<val[(cur<<1)]<<' '<<lazy[(cur<<1)+1]<<' '<<val[(cur<<1)+1]<<endl;
		lazy[(cur<<1)]+=lazy[cur];
		val[(cur<<1)]+=lazy[cur];
		lazy[(cur<<1)+1]+=lazy[cur];
		val[(cur<<1)+1]+=lazy[cur];
	//	cout<<"after: "<<lazy[(cur<<1)]<<' '<<val[(cur<<1)]<<' '<<lazy[(cur<<1)+1]<<' '<<val[(cur<<1)+1]<<endl;
		lazy[cur]=0;
	}
	void updateK(int l, int r, int cur, int tl, int tr, int d)
	{
		if ((tl>r)or(tr<l)) return;
		if ((tl<=l)and(tr>=r)) 
		{
	//		cout<<"update directly "<<cur<<' '<<d<<endl;
	//		cout<<"before: "<<val[cur]<<' '<<lazy[cur]<<endl;
			val[cur]+=d;
			lazy[cur]+=d;
	//		cout<<"after: "<<val[cur]<<' '<<lazy[cur]<<endl;
		}
		else
		{
			int mid=(l+r)/2;
			flusha(cur);
			updateK(l,mid,(cur<<1),tl,tr,d);
			updateK(mid+1,r,(cur<<1)+1,tl,tr,d);
			val[cur]=max(val[(cur<<1)],val[(cur<<1)+1]);
		}
	}
	void update(int l, int r, int d)
	{
		if (l>r) return;
		updateK(1,n,1,l,r,d);
	//	debug();
	}
	void debugK(int l, int r, int cur)
	{
		cout<<"---------------------------------\n";
		cout<<"Now crawling node: "<<cur<<endl;
		cout<<"Covering range: ("<<l<<","<<r<<")"<<endl;
		cout<<"It's values: "<<"val = "<<val[cur]<<" lazy = "<<lazy[cur]<<endl;
		cout<<"---------------------------------\n";
		int mid=(l+r)/2;
		if (l<r)
		{
		debugK(l,mid,(cur<<1));
		debugK(mid+1,r,(cur<<1)+1);
		}
	}
	void debug()
	{
		debugK(1,n,1);
	}
	int getK(int l, int r, int cur, int tl, int tr)
	{
		if ((tl>r)or(tr<l)) return -1;
		if ((tl<=l)and(tr>=r)) 
		{
			return val[cur];
		}
		else
		{
			int mid=(l+r)/2;
			flusha(cur);
			int aa=getK(l,mid,(cur<<1),tl,tr);
			int bb=getK(mid+1,r,(cur<<1)+1,tl,tr);
			return max(aa,bb);
		}
	}
	int get(int l, int r)
	{
		if (l>r) return -1;
		return getK(1,n,1,l,r);
	}
};
 seg st;


vector<int> vec;
vector<pii(int)> cand;
int n,m,i,j,k,t,t1,u,v,a,b;
int arr[100001];
set<int> anc;
int ql[500001],qr[500001],qx[500001];
vector<int> qbuc[500001];
vector<int> pbuc[500001];
int main()
{
	fio;
	cin>>n;
	for (i=1;i<=n;i++) {
		cin>>arr[i];
		vec.push_back(i);	
	}
	sort(vec.begin(),vec.end(),[](int a, int b){
		return (arr[a]>arr[b]);
	});
	j=0;
	for (i=0;i<n;i++) {
		if (!i || arr[vec[i]]==arr[vec[i-1]]) continue; else {
			for (k=j;k<i;k++) {
				anc.insert(vec[k]);
			}
			for (k=j;k<i;k++) {
				auto it = anc.lower_bound(vec[k]);
				auto it2 = it;
				it2++;
				if (it2!=anc.end()) {
					cand.push_back({vec[k],(*it2)});
				}
				it2=it;
				if (it2!=anc.begin()) {
					it2--;
					cand.push_back({(*it2),vec[k]});
				}
			}
			j=i;
		}
	}

	{
			for (k=j;k<i;k++) {
				anc.insert(vec[k]);
			}
			for (k=j;k<i;k++) {
				auto it = anc.lower_bound(vec[k]);
				auto it2 = it;
				it2++;
				if (it2!=anc.end()) {
					cand.push_back({vec[k],(*it2)});
				}
				it2=it;
				if (it2!=anc.begin()) {
					it2--;
					cand.push_back({(*it2),vec[k]});
				}
			}
			j=i;
		}



	for (auto g : cand) {
		// cout<<g.fi<<' '<<g.se<<endl;
		pbuc[g.fi].push_back(g.se);
	}
	cin>>m;
	for (i=1;i<=m;i++) {
		cin>>ql[i]>>qr[i];
		qbuc[ql[i]].push_back(i);
	}
	st1.reset(1,1,n);
	for (i=1;i<=n;i++) {
		star[i]=arr[i]-1e9;
	}
	st.reset(n);
	for (i=n;i>=1;i--) {
		for (auto g : pbuc[i]) {
			u=2*g-i;
			if (u<=n) {
				v=0;
				while(true) {
					v++;
					if (v==100) break;
					auto gg = st1.get(1,1,n,u,n);
					// cout<<gg.p1<<' '<<gg.p2<<' '<<gg.p3<<endl;
					if (gg.p1>=arr[i]+arr[g]) {
						break;
					} else {
						st.update(gg.p2,gg.p3,(arr[i]+arr[g]-gg.p1));
						st1.upd(1,1,n,gg.p2,gg.p3,arr[i]+arr[g]);
					}
				}
			}
		}
		for (auto g : qbuc[i]) {
			qx[g] = st.get(ql[g],qr[g]);
		}
	}
	for (i=1;i<=m;i++) {
		cout<<qx[i]<<endl;
	}
}
// N;	

Compilation message

jumps.cpp:23: warning: ignoring '#pragma comment ' [-Wunknown-pragmas]
   23 | #pragma comment(linker, "/stack:200000000")
      |
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 23756 KB Output is correct
2 Incorrect 13 ms 23880 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 23756 KB Output is correct
2 Incorrect 13 ms 23880 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 48 ms 49844 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 23756 KB Output is correct
2 Incorrect 13 ms 23880 KB Output isn't correct
3 Halted 0 ms 0 KB -