Submission #29523

# Submission time Handle Problem Language Result Execution time Memory
29523 2017-07-20T05:06:04 Z 서규호(#1242) Lightning Conductor (POI11_pio) C++14
27 / 100
143 ms 5036 KB
#include <bits/stdc++.h>
#include <unistd.h>

#define pii pair<int,int>
#define pll pair<lld,lld>
#define pb push_back
#define next nextt
#define left leftt
#define right rightt
#define lld long long
#define Inf 1000000000
#define Mod 1000000007
#define Linf 1000000000000000000LL
#define get gett

using namespace std;

int N,ans;
int a[500002];

struct data{
	deque<pii> q;
	void insert(int x){
		while(!q.empty() && q.back().first <= a[x]) q.pop_back();
		q.pb({a[x],x});
	}
	int get(){
		return q.front().first;
	}
	void erase(int x){
		if(q.front().second == x) q.pop_front();
	}
	bool empty(){
		return (q.size() == 0);
	}
}S1[800],S2[800];

void calcans(int num){
	ans = 0;
	int e = sqrt(N-1);
	if(e*e != N-1) e++;
	for(int i=1; i<=e; i++){
		if(!S1[i].empty()){
			ans = max(ans,S1[i].get()+i-a[num]);
		}
		if(!S2[i].empty()){
			ans = max(ans,S2[i].get()+i-a[num]);
		}
	}
}

int main(){
	scanf("%d",&N);
	for(int i=1; i<=N; i++){
		scanf("%d",&a[i]);
	}
	for(int i=2; i<=N; i++){
		int t = sqrt(i-1);
		if(t*t != i-1) t++;
		S2[t].insert(i);
	}
	calcans(1);
	printf("%d\n",ans);
	for(int i=2; i<=N; i++){
		S1[1].insert(a[i-1]);
		for(int j=1; i-1-j*j>=1; j++){
			int t = i-1-j*j;
			S1[j].erase(t);
			S1[j+1].insert(t);
		}
		S2[1].erase(i);
		for(int j=1; i+j*j<=N; j++){
			int t = i+j*j;
			S2[j+1].erase(t);
			S2[j].insert(t);
		}
		calcans(i);
		printf("%d\n",ans);
	}

	return 0;
}

Compilation message

pio.cpp: In function 'int main()':
pio.cpp:53:16: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&N);
                ^
pio.cpp:55:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&a[i]);
                    ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 5036 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 5036 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5036 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 6 ms 5036 KB Execution killed with signal 11 (could be triggered by violating memory limits)
# Verdict Execution time Memory Grader output
1 Runtime error 16 ms 5036 KB Execution killed with signal 11 (could be triggered by violating memory limits)
# Verdict Execution time Memory Grader output
1 Runtime error 9 ms 5036 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 23 ms 5036 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 66 ms 5036 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 93 ms 5036 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 103 ms 5036 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 143 ms 5036 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -