Submission #201035

# Submission time Handle Problem Language Result Execution time Memory
201035 2020-02-09T06:44:26 Z ryansee Jousting tournament (IOI12_tournament) C++14
0 / 100
52 ms 13968 KB
#include "bits/stdc++.h"
using namespace std;

#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define eb emplace_back
#define ins insert
#define ph push
#define f first
#define s second
#define cbr cerr << "hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ll(x.size())
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
inline long long rand(long long x, long long y) { return (rng() % (y+1-x)) + x; } //inclusivesss
string inline to_string(char c) {string s(1,c);return s;} template<typename T> inline T gcd(T a,T b){ return a==0?llabs(b):gcd(b%a,a); }

typedef long long ll; 
typedef long double ld;
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
typedef pair<ll,ll>pi; typedef pair<ll,pi>spi; typedef pair<pi,pi>dpi;

#define LLINF ((long long) 1e18)//1234567890987654321
#define INF 1234567890ll
// #define cerr if(0)cout
#define MAXN (100006)
ll n, c, r, A[MAXN];
multiset<pi> ms; // no partial intersection, only full intersection
struct node {
	int s,e,m;
	ll v;
	node *l,*r;
	node(int S,int E) {
		s=S,e=E,m=(s+e)>>1;
		if(s^e) {
			l=new node(s,m);
			r=new node(m+1,e);
			v=max(l->v,r->v);
		} else v=A[s];
	}
	ll rmq(int x,int y){
	    if(x>y) return -LLINF;
		if(s==x&&e==y) return v;
		if(x>m) return r->rmq(x,y);
		else if(y<=m) return l->rmq(x,y);
		else return max(l->rmq(x,m),r->rmq(m+1,y));
	}
} *seg;
struct fen {
	ll fw[MAXN];
	void update(int x,int y,ll nval) {
		++ x, ++ y;
		assert(x>0&&y+1>0);
		pupdate(x,nval);
		pupdate(y+1,-nval);
	}
	void pupdate(int x,ll nval) {
		for(;x<MAXN;x+=x&(-x)) fw[x]+=nval;
	}
	ll sum(ll x) { // point sum
		++ x; ll res=0;
		assert(x>0);
		for(;x;x-=x&(-x)) res+=fw[x];
		return res;
	}
} fen;
int GetBestPosition(int N, int C, int R, int *K, int *S, int *E) {
	n=N, c=C, r=R;
	FOR(i,0,n-2)A[i]=K[i];
	seg=new node(0,n-2);
	FOR(i,0,C-1) {
		auto [s,e] = tie(S[i],E[i]);
		while(ms.size()) {
			int no=0;
			auto b4=ms.lower_bound(pi(s,0));
			if(b4 != ms.begin() && (--b4)->s >= s) { // intersect with front
				ll val=b4->s-s;
				s=b4->f-val; 
				ms.erase(b4);
			} else ++ no;
			auto aft=ms.lower_bound(pi(s,0));
			if(aft != ms.end() && aft->f <= e) { // intersect with back
				ll val=e-aft->f;
				e=aft->s+val;
				ms.erase(aft);
			} else ++ no;
			if(no==2) break;
		}
		ms.ins(pi(s,e));
		tie(S[i],E[i])=tie(s,e);
	}
// 	assert(S[C-1]==0&&E[C-1]==n-1);
	FOR(i,0,C-1) {
	    assert(E[i]-1<=n-2);
		if(seg->rmq(S[i], E[i]-1) < r) {
			fen.update(S[i], E[i], 1);
		}
	}
	ll mx=-LLINF, pos=-1;
	FOR(i,0,n-1) {
		if(fen.sum(i) > mx) mx=fen.sum(i), pos=i;
	}
	return int(pos);
}

Compilation message

tournament.cpp: In function 'int GetBestPosition(int, int, int, int*, int*, int*)':
tournament.cpp:76:8: warning: decomposition declaration only available with -std=c++1z or -std=gnu++1z
   auto [s,e] = tie(S[i],E[i]);
        ^
# Verdict Execution time Memory Grader output
1 Runtime error 6 ms 504 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 7 ms 888 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 52 ms 13968 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -