답안 #197603

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
197603 2020-01-21T21:12:54 Z stefdasca Watering can (POI13_kon) C++14
100 / 100
431 ms 16964 KB
#include<bits/stdc++.h>
#include "koninc.h"
using namespace std;

const int MAXN = 300001;

int N, K, v[MAXN+5];

struct nod
{
    int mn, cnt;
    int lazy;
};
nod aint[MAXN * 4 + 5];
void solve_lazy(int nod)
{
    if(2 * nod + 1 <= 4 * N)
    {
        aint[2 * nod].lazy += aint[nod].lazy;
        aint[2 * nod + 1].lazy += aint[nod].lazy;
    }
    aint[nod].lazy = 0;
}
void build(int nod, int left, int right)
{
    if(left == right)
    {
        aint[nod].mn = K - v[left];
        if(aint[nod].mn <= 0)
            aint[nod] = {(1<<30), 1, 0};
        return;
    }
    int mid = (left + right) / 2;
    build(2 * nod, left, mid);
    build(2 * nod + 1, mid + 1, right);
    aint[nod].cnt = aint[2 * nod].cnt + aint[2 * nod + 1].cnt;
    aint[nod].mn = min(aint[2 * nod].mn + aint[2 * nod].lazy, aint[2 * nod + 1].mn + aint[2 * nod + 1].lazy);
}

void update(int nod, int left, int right, int l, int r)
{
    if(l <= left && right <= r && aint[nod].mn + aint[nod].lazy - 1 > 0)
    {
        aint[nod].lazy--;
        return ;
    }
    if(left == right)
    {
        aint[nod] = {(1<<30), 1, 0};
        return ;
    }
    solve_lazy(nod);
    int mid = (left + right) / 2;
    if(l <= mid)
        update(2 * nod, left, mid, l, r);
    if(mid < r)
        update(2 * nod + 1, mid + 1, right, l, r);
    aint[nod].cnt = aint[2 * nod].cnt + aint[2 * nod + 1].cnt;
    aint[nod].mn = min(aint[2 * nod].mn + aint[2 * nod].lazy, aint[2 * nod + 1].mn + aint[2 * nod + 1].lazy);
}

int query(int nod, int left, int right, int l, int r)
{
    if(l <= left && right <= r)
        return aint[nod].cnt;
    int mid = (left + right) / 2;
    int ans = 0;
    if(l <= mid)
        ans += query(2 * nod, left, mid, l, r);
    if(mid < r)
        ans += query(2 * nod + 1, mid + 1, right, l, r);
    return ans;
}
void inicjuj(int n, int k, int *D)
{
    N = n, K = k;
    for(int i = 1; i <= n; ++i)
        v[i] = D[i-1];
    build(1, 1, n);
}

void podlej(int a, int b)
{
    ++a, ++b;
    update(1, 1, N, a, b);
}

int dojrzale(int a, int b)
{
    ++a, ++b;
    return query(1, 1, N, a, b);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 54 ms 1500 KB Output is correct
2 Correct 46 ms 1380 KB Output is correct
3 Correct 48 ms 1528 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 66 ms 2524 KB Output is correct
2 Correct 79 ms 2268 KB Output is correct
3 Correct 66 ms 2424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 99 ms 4516 KB Output is correct
2 Correct 92 ms 4532 KB Output is correct
3 Correct 106 ms 2936 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 214 ms 5244 KB Output is correct
2 Correct 150 ms 5088 KB Output is correct
3 Correct 176 ms 4600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 225 ms 5288 KB Output is correct
2 Correct 185 ms 8060 KB Output is correct
3 Correct 218 ms 5404 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 313 ms 9420 KB Output is correct
2 Correct 298 ms 8400 KB Output is correct
3 Correct 341 ms 9340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 411 ms 16388 KB Output is correct
2 Correct 376 ms 16852 KB Output is correct
3 Correct 392 ms 16696 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 431 ms 16548 KB Output is correct
2 Correct 430 ms 16964 KB Output is correct
3 Correct 368 ms 15992 KB Output is correct