Submission #343445

# Submission time Handle Problem Language Result Execution time Memory
343445 2021-01-03T23:48:14 Z iliccmarko Watering can (POI13_kon) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
#include "koninc.h"
using namespace std;
#define ll long long
#define endl "\n"
#define INF 1000000000
#define LINF 1000000000000000LL
#define pb push_back
#define all(x) x.begin(), x.end()
#define len(s) (int)s.size()
#define test_case { int t; cin>>t; while(t--)solve(); }
#define single_case solve();
#define line cerr<<"----------"<<endl;
#define ios { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cerr.tie(NULL); }
#define mod 1000000007LL
const int N = 3e5 + 50;
vector<int> sum(4*N), maks(4*N);
vector<int> a(N);
int d;
vector<int> lazy(4*N);
int n;

int buildsum(int node, int l, int r)
{
    if(l==r)
    {
        return sum[node] = (a[l]>=d)?1:0;
    }
    int mid = (l+r)/2;
    return sum[node] = buildsum(node*2+1, l, mid) + buildsum(node*2+2, mid+1, r);
}

int buildmaks(int node, int l, int r)
{
    if(l==r)
    {
        if(a[l]>=d) maks[node] = -N;
        else maks[node] = a[l];
        return maks[node];
    }
    int mid = (l+r)/2;
    maks[node] = max(buildmaks(node*2+1, l, mid), buildmaks(node*2+2, mid+1, r));
}

void updatemaks(int node, int l, int r, int i, int j)
{
    if(i>j) return;
    int mid = (i+j)/2;
    if(lazy[node])
    {
        if(i!=j)
        {
            lazy[node*2+1] += lazy[node];
            lazy[node*2+2] += lazy[node];
        }
        maks[node] += lazy[node];
        lazy[node] = 0;
    }
    if(i>r||j<l) return;
    if(i>=l&&j<=r)
    {
        maks[node]++;
        if(i!=j)
        {
            lazy[node*2+1]++;
            lazy[node*2+2]++;
        }
        return;
    }
    updatemaks(node*2+1, l, r, i, mid);
    updatemaks(node*2+2, l, r, mid+1, j);
    maks[node] = max(maks[node*2+1], maks[node*2+2]);
}

void updatesum(int node, int l, int r, int x)
{
    if(l>r) return;
    if(l==r)
    {
        sum[node] = 1;
        return;
    }
    int mid = (l+r)/2;
    if(x>mid) updatesum(node*2+2, mid+1, r, x);
    else updatesum(node*2+1, l, mid, x);
    sum[node] = sum[node*2+1] + sum[node*2+2];
}

int get_sum(int node, int l, int r, int i, int j)
{
    if(i>j) return 0;
    if(i>r||j<l) return 0;
    if(i>=l&&j<=r) return sum[node];
    int mid = (i+j)/2;
    get_sum(node*2+1, l, r, i, mid) + get_sum(node*2+2, l, r, mid+1, j);
}

void trazi(int node, int l, int r)
{
    if(l>r) return;
    int mid = (l+r)/2;
    if(lazy[node])
    {
        if(l!=r)
        {
            lazy[node*2+1] += lazy[node];
            lazy[node*2+2] += lazy[node];
        }
        maks[node] += lazy[node];
        lazy[node] = 0;
    }
    if(maks[node]<d) return;
    if(l==r)
    {
        updatesum(0, 0, n-1, l);
        maks[node] = -N;
        return;
    }
    //int mid = (l+r)/2;
    trazi(node*2+1, l, mid);
    trazi(node*2+2, mid+1, r);
    maks[node] = max(maks[node*2+1], maks[node*2+2]);
}

void inicjuj(int w, int k, int *D)
{
    for(int i = 0;i<w;i++) a[i] = D[i];
    d = k;
    n = w;
    buildmaks(0, 0, n-1);
    buildsum(0, 0, n-1);
}

void podlej(int a, int b)
{
    updatemaks(0, a, b, 0, n-1);
}

int dojrzale(int a, int b)
{
    trazi(0, 0, n-1);
    return get_sum(0, a, b, 0, n-1);
}

int main()
{
   // ios
    int D[MAXN];
    int num_calls, i;
    int n, k;
    scanf("%d%d", &n, &k);
    for (i = 0; i < n; ++i)
        scanf("%d", &D[i]);

    inicjuj(n,k, D);

    scanf("%d", &num_calls);
    for (i = 1; i <= num_calls; i++)
    {
        char call[2];
        int a, b;
        scanf("%s%d%d", call, &a, &b);
        if (call[0] == 'p')
            podlej(a, b);
        else
            printf("%d\n", dojrzale(a, b));
    }
    return 0;





    return 0;
}

Compilation message

kon.cpp: In function 'int get_sum(int, int, int, int, int)':
kon.cpp:95:37: warning: value computed is not used [-Wunused-value]
   95 |     get_sum(node*2+1, l, r, i, mid) + get_sum(node*2+2, l, r, mid+1, j);
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
kon.cpp: In function 'int main()':
kon.cpp:148:11: error: 'MAXN' was not declared in this scope
  148 |     int D[MAXN];
      |           ^~~~
kon.cpp:153:22: error: 'D' was not declared in this scope
  153 |         scanf("%d", &D[i]);
      |                      ^
kon.cpp:155:18: error: 'D' was not declared in this scope
  155 |     inicjuj(n,k, D);
      |                  ^
kon.cpp: In function 'int buildmaks(int, int, int)':
kon.cpp:42:16: warning: control reaches end of non-void function [-Wreturn-type]
   42 |     maks[node] = max(buildmaks(node*2+1, l, mid), buildmaks(node*2+2, mid+1, r));
kon.cpp: In function 'int get_sum(int, int, int, int, int)':
kon.cpp:95:46: warning: control reaches end of non-void function [-Wreturn-type]
   95 |     get_sum(node*2+1, l, r, i, mid) + get_sum(node*2+2, l, r, mid+1, j);
      |                                       ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
kon.cpp: In function 'int main()':
kon.cpp:151:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  151 |     scanf("%d%d", &n, &k);
      |     ~~~~~^~~~~~~~~~~~~~~~
kon.cpp:157:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  157 |     scanf("%d", &num_calls);
      |     ~~~~~^~~~~~~~~~~~~~~~~~
kon.cpp:162:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  162 |         scanf("%s%d%d", call, &a, &b);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~