답안 #47366

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
47366 2018-05-01T16:40:46 Z tieunhi Lightning Conductor (POI11_pio) C++14
54 / 100
428 ms 12744 KB
#include <bits/stdc++.h>
#define pii pair<int, int>
#define mp make_pair
#define F first
#define S second
#define PB push_back
#define maxc 1000000007
#define N 500005
using namespace std;

struct Dequeue
{
    int a[N];
    int top, bot;
    Dequeue()
    {
        bot = 0;
        top = 1;
    }
    void push_back(int x) {a[++bot] = x;}
    void pop_back() {bot--;}
    void pop_front() {top++;}
    int back() {return a[bot];}
    int front() {return a[top];}
    bool empty() {return (bot < top);}
}q;
int n, a[N], x2[N], res[N], delta[N];

void inline MAX(int &A, int B) {A = max(A, B);}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //freopen("INP.TXT", "r", stdin);
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    for (int i = 1; i <= sqrt(n) + 1; i++)
        x2[i] = i*i;
    for (int i = 1; i <= sqrt(n) + 1; i++)
        delta[i] = x2[i] - x2[i-1];

    for (int can = 1; can <= sqrt(n)+1; can++)
    {
        int len = delta[can];
        while (!q.empty()) q.pop_back();
        for (int i = 1; i <= n; i++)
        {
            int pos = i - x2[can-1] - 1;
            while (!q.empty() && q.front() <= pos - len)
                q.pop_front();

            if (pos > 0)
            {
                while (!q.empty() && a[q.back()] <= a[pos])
                    q.pop_back();
                q.push_back(pos);
            }
            if (!q.empty()) MAX(res[i], a[q.front()] + can);
        }

        while (!q.empty()) q.pop_back();
        for (int i = n; i >= 1; i--)
        {
            int pos = i + x2[can-1] + 1;
            while (!q.empty() && q.front() >= pos + len)
                q.pop_front();

            if (pos <= n)
            {
                while (!q.empty() && a[q.back()] <= a[pos])
                    q.pop_back();
                q.push_back(pos);
            }
            if (!q.empty()) MAX(res[i], a[q.front()] + can);
        }
    }
    for (int i = 1; i <= n; i++)
        if (res[i] <= a[i]) cout <<0<<'\n';
        else cout <<res[i] - a[i]<<'\n';

}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 484 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 484 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 143 ms 1876 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 260 ms 2840 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 428 ms 3088 KB Output is correct
2 Correct 138 ms 3088 KB Output is correct
3 Correct 380 ms 3436 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 97 ms 6268 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 43 ms 8428 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 59 ms 10300 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 80 ms 12536 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 104 ms 12744 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -