Submission #964493

# Submission time Handle Problem Language Result Execution time Memory
964493 2024-04-17T01:55:31 Z pcc The Potion of Great Power (CEOI20_potion) C++17
70 / 100
3000 ms 155604 KB
#include <bits/stdc++.h>
using namespace std;

#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,popcnt,sse4")
#define pii pair<int,int>
#define fs first
#define sc second
#define ll long long

const int mxn = 2e5+10;

int nid[mxn*100],val[mxn*100];
int vcnt = 0;

struct node{
	int head;
	int pl,pr;
};

int add(int now,int v){
	vcnt++;
	nid[vcnt] = now;
	val[vcnt] = v;
	return vcnt;
}

struct SEG{
#define mid ((l+r)>>1)
#define ls seg[now].pl
#define rs seg[now].pr
	node seg[mxn*50];
	int ppp = 0;
	SEG(){}
	int newnode(){
		return ++ppp;
	}
	int modify(int now,int l,int r,int s,int e,int v){
		if(!now)now = newnode();
		if(l>=s&&e>=r){
			seg[now].head = add(seg[now].head,v);
			return now;
		}
		if(mid>=s)ls = modify(ls,l,mid,s,e,v);
		if(mid<e)rs = modify(rs,mid+1,r,s,e,v);
		return now;
	}
	int re[mxn],ptr = 0;
	void addv(int v){
		re[ptr++] = v;
		return;
	}
	void getval(int now,int l,int r,int p){
		if(!now)return;
		for(int i = seg[now].head;i;i = nid[i])addv(val[i]);
		if(l == r)return;
		if(mid>=p)getval(ls,l,mid,p);
		else getval(rs,mid+1,r,p);
		return;
	}
#undef ls
#undef rs
#undef mid
};

SEG seg;
int arr[mxn],N,D;
int rt[mxn];

void init(int NN, int DD, int H[]) {
	N = NN,D = DD;
	for(int i = 0;i<N;i++){
		arr[i] = H[i];
	}
	return;
}

void curseChanges(int U, int A[], int B[]) {
	map<ll,int> mp;
	for(int i = 0;i<U;i++){
		pii p = {A[i],B[i]};
		if(p.fs>p.sc)swap(p.fs,p.sc);
		ll h = 1ll*p.fs*mxn+p.sc;
		if(mp.find(h) != mp.end()){
			rt[p.fs] = seg.modify(rt[p.fs],0,mxn-10,mp[h]+1,i,arr[p.sc]);
			rt[p.sc] = seg.modify(rt[p.sc],0,mxn-10,mp[h]+1,i,arr[p.fs]);
			mp.erase(h);
		}
		else{
			mp[h] = i;
		}
	}
	for(auto &i:mp){
		pii p = pii(i.fs/mxn,i.fs%mxn);
		rt[p.fs] = seg.modify(rt[p.fs],0,mxn-10,i.sc+1,mxn-10,arr[p.sc]);
		rt[p.sc] = seg.modify(rt[p.sc],0,mxn-10,i.sc+1,mxn-10,arr[p.fs]);
	}
	return;
}

unordered_map<ll,int> done;

int question(int x, int y, int v) {
	if(done.find(1ll*x*mxn*mxn+1ll*y*mxn+v) != done.end())return done[1ll*x*mxn*mxn+1ll*y*mxn+v];
	seg.ptr = 0;seg.getval(rt[x],0,mxn-10,v);
	vector<int> ta;
	for(int i = 0;i<seg.ptr;i++){
		ta.push_back(seg.re[i]);
	}
	seg.ptr = 0;seg.getval(rt[y],0,mxn-10,v);
	vector<int> tb;
	for(int i = 0;i<seg.ptr;i++){
		tb.push_back(seg.re[i]);
	}
	sort(ta.begin(),ta.end());
	sort(tb.begin(),tb.end());
	int pt = 0;
	int ans = 1e9;
	for(auto &i:ta){
		while(pt != tb.size()&&tb[pt]<i)pt++;
		if(pt != tb.size())ans = min(ans,abs(i-tb[pt]));
		if(pt-1>=0)ans = min(ans,abs(i-tb[pt-1]));
	}
	return done[1ll*x*mxn*mxn+1ll*y*mxn+v] = done[1ll*x*mxn*mxn+1ll*y*mxn+v] = ans;
}

Compilation message

potion.cpp: In function 'int question(int, int, int)':
potion.cpp:120:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  120 |   while(pt != tb.size()&&tb[pt]<i)pt++;
      |         ~~~^~~~~~~~~~~~
potion.cpp:121:9: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  121 |   if(pt != tb.size())ans = min(ans,abs(i-tb[pt]));
      |      ~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 8536 KB Output is correct
2 Correct 4 ms 8536 KB Output is correct
3 Correct 3 ms 8536 KB Output is correct
4 Correct 11 ms 9812 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 468 ms 155472 KB Output is correct
2 Correct 431 ms 155272 KB Output is correct
3 Correct 179 ms 59216 KB Output is correct
4 Correct 1791 ms 98864 KB Output is correct
5 Correct 819 ms 132280 KB Output is correct
6 Correct 861 ms 115144 KB Output is correct
7 Correct 606 ms 126104 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 424 ms 155604 KB Output is correct
2 Correct 1506 ms 79640 KB Output is correct
3 Correct 1440 ms 118512 KB Output is correct
4 Correct 2453 ms 115056 KB Output is correct
5 Correct 512 ms 152988 KB Output is correct
6 Correct 2503 ms 115260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 61 ms 15748 KB Output is correct
2 Correct 87 ms 13112 KB Output is correct
3 Correct 79 ms 11540 KB Output is correct
4 Correct 650 ms 14044 KB Output is correct
5 Correct 646 ms 14868 KB Output is correct
6 Correct 123 ms 13836 KB Output is correct
7 Correct 459 ms 12448 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8536 KB Output is correct
2 Correct 4 ms 8536 KB Output is correct
3 Correct 4 ms 8536 KB Output is correct
4 Correct 3 ms 8536 KB Output is correct
5 Correct 11 ms 9812 KB Output is correct
6 Correct 468 ms 155472 KB Output is correct
7 Correct 431 ms 155272 KB Output is correct
8 Correct 179 ms 59216 KB Output is correct
9 Correct 1791 ms 98864 KB Output is correct
10 Correct 819 ms 132280 KB Output is correct
11 Correct 861 ms 115144 KB Output is correct
12 Correct 606 ms 126104 KB Output is correct
13 Correct 424 ms 155604 KB Output is correct
14 Correct 1506 ms 79640 KB Output is correct
15 Correct 1440 ms 118512 KB Output is correct
16 Correct 2453 ms 115056 KB Output is correct
17 Correct 512 ms 152988 KB Output is correct
18 Correct 2503 ms 115260 KB Output is correct
19 Correct 61 ms 15748 KB Output is correct
20 Correct 87 ms 13112 KB Output is correct
21 Correct 79 ms 11540 KB Output is correct
22 Correct 650 ms 14044 KB Output is correct
23 Correct 646 ms 14868 KB Output is correct
24 Correct 123 ms 13836 KB Output is correct
25 Correct 459 ms 12448 KB Output is correct
26 Correct 763 ms 69696 KB Output is correct
27 Correct 1784 ms 118472 KB Output is correct
28 Correct 1687 ms 137260 KB Output is correct
29 Correct 1833 ms 98864 KB Output is correct
30 Execution timed out 3071 ms 115052 KB Time limit exceeded
31 Halted 0 ms 0 KB -