답안 #482107

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
482107 2021-10-23T08:33:00 Z MilosMilutinovic Watering can (POI13_kon) C++14
10 / 100
416 ms 15792 KB
#include <bits/stdc++.h>
#define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
#define fb(i,a,b) for(int (i) = (a); (i) >= (b); --(i))
#define pb push_back

#define gas INT_MAX

using namespace std;

int N,K;

int niz[300005];

int mn[1000005];
int cnt[1000005];
int lzy[1000005];


void upd(int node){
    cnt[node] = cnt[node * 2] + cnt[node * 2 + 1];
    mn[node] = min(mn[node * 2], mn[node * 2 + 1]);
}

void build(int node, int l, int r){
    if(l == r){
        if(niz[l] > 0)mn[node] = niz[l];
        else{
            cnt[node] = 1;
            mn[node] = 1e9;
        }
        return;
    }
    int mid = (l + r) / 2;
    build(node * 2, l, mid);
    build(node * 2 + 1, mid + 1, r);
    upd(node);
}

void propagate(int node){
    if(mn[node] != 1e9)mn[node] -= lzy[node];
    lzy[node * 2] += lzy[node];
    lzy[node * 2 + 1] += lzy[node];
    lzy[node] = 0;
}

void update(int node, int l, int r, int ll, int rr, int x){
    if(l > r || l > rr || r < ll)return;
    if(ll <= l && r <= rr){
        lzy[node] += x;
        propagate(node);
        return;
    }
    propagate(node);
    int mid = (l + r) / 2;
    update(node * 2, l, mid, ll, rr, x);
    update(node * 2 + 1, mid + 1, r, ll, rr, x);
    upd(node);
}

int get(int node, int l, int r, int ll, int rr){
    propagate(node);
    if(l > r || l > rr || r < ll)return 0;
    if(ll <= l && r <= rr)return cnt[node];
    int mid = (l + r) / 2;
    return get(node * 2, l, mid, ll, rr) + get(node * 2 + 1, mid + 1, r, ll, rr);
}

void rebuild(int node, int l, int r){
    propagate(node);
    if(mn[node] > 0)return;
    if(l == r){
        mn[node] = 1e9;
        cnt[node] = 1;
        return;
    }
    int mid = (l + r) / 2;
    rebuild(node * 2, l, mid);
    rebuild(node * 2 + 1, mid + 1, r);
    upd(node);
}

void inicjuj(int n, int k, int *D)
{
    N = n;
    K = k;
    ff(i,1,n)niz[i] = k-D[i-1];
    build(1, 1, N);
}

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

int dojrzale(int a, int b)
{
    a++;
    b++;
    return get(1, 1, N, a, b);
}

Compilation message

kon.cpp: In function 'void inicjuj(int, int, int*)':
kon.cpp:2:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    2 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
kon.cpp:86:5: note: in expansion of macro 'ff'
   86 |     ff(i,1,n)niz[i] = k-D[i-1];
      |     ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1484 KB Output is correct
2 Incorrect 1 ms 1484 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 1484 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 44 ms 2776 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 59 ms 4000 KB Output is correct
2 Correct 76 ms 3748 KB Output is correct
3 Correct 66 ms 3832 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 78 ms 6220 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 209 ms 6788 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 230 ms 6916 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 292 ms 11484 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 416 ms 15748 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 373 ms 15792 KB Output isn't correct
2 Halted 0 ms 0 KB -