답안 #942434

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
942434 2024-03-10T16:05:39 Z KG07 사탕 분배 (IOI21_candies) C++17
0 / 100
345 ms 43000 KB
#include "candies.h"

#include <bits/stdc++.h>
using namespace std;

struct segment_tree{
    long long vmax[600006], vmin[600006], lazy[600006], m;
    int n;
    void init(int N){
        n = N;
        m = 0LL;
        for(int i = 0; i < 600006; i++){
            vmax[i] = 0LL;
            vmin[i] = 0LL;
            lazy[i] = 0LL;
        }
    }
    void lazy_update(int N){
        lazy[2*N] += lazy[N];
        lazy[2*N+1] += lazy[N];
        vmax[2*N] += lazy[N];
        vmin[2*N] += lazy[N];
        vmax[2*N+1] += lazy[N];
        vmin[2*N+1] += lazy[N];
        lazy[N] = 0;
    }
    long long get_max(int N, int l, int r, int s, int t){
        if(l > t || s > r)return -9000000000000000000LL;
        if(l <= s && t <= r)return vmax[N];
        return max(get_max(2*N, l, r, s, (s+t)/2), get_max(2*N+1, l, r, (s+t)/2+1, t));
    }
    long long get_min(int N, int l, int r, int s, int t){
        if(l > t || s > r)return 9000000000000000000LL;
        if(l <= s && t <= r)return vmin[N];
        return max(get_min(2*N, l, r, s, (s+t)/2), get_min(2*N+1, l, r, (s+t)/2+1, t));
    }
    void update(int N, int M, int l, int r, int s, int t){
        if(s == 1 && t == n)m += M;
        if(l > t || s > r)return;
        if(l <= s && t <= r){
            vmax[N] += M;
            vmin[N] += M;
            lazy[N] += M;
            return;
        }
        lazy_update(N);
        update(2*N, M, l, r, s, (s+t)/2);
        update(2*N+1, M, l, r, (s+t)/2+1, t);
        vmax[N] = max(vmax[2*N], vmax[2*N+1]);
        vmin[N] = min(vmin[2*N], vmin[2*N+1]);
    }
    pair<int, int> find_index(int N, int M, int l, int r, long long s, long long t){
        if(l == r)return make_pair(vmax[N], max(s, vmax[N])+min(t, vmin[N])-vmin[N]);
        lazy_update(N);
        if(max(s, vmax[2*N+1])-min(t, vmin[2*N+1])<M)return find_index(2*N, M, l, (l+r)/2, max(s, vmax[2*N+1]), min(t, vmin[2*N+1]));
        return find_index(2*N+1, M, (l+r)/2+1, r, s, t);
    }
} A;

vector<int> distribute_candies(vector<int> c, vector<int> l, vector<int> r, vector<int> v) {
    int n = c.size(), q = v.size();
    A.init(q+1);
    vector<vector<int>> x(n), y(n);
    for(int i = 0; i < q; i++){
        x[l[i]].push_back(i);
        if(r[i]<n-1)y[r[i]+1].push_back(i);
    }
    vector<int> s(n);
    for(int i = 0; i < n; i++){
        for(int j = 0; j < x[i].size(); j++)A.update(1, v[x[i][j]], x[i][j]+2, q+1, 1, q+1);
        for(int j = 0; j < y[i].size(); j++)A.update(1, -v[y[i][j]], y[i][j]+2, q+1, 1, q+1);
        //for(int j = 1; j < 6; j++)cout << A.vmax[j] << " " << A.vmin[j] << " " << A.lazy[j] << "\n";
        pair<int, int> t = A.find_index(1, c[i], 1, q+1, -9000000000000000000LL, 9000000000000000000LL);
        s[i] = t.first > t.second ? A.m - t.second : A.m - t.second + c[i];
    }

    return s;
}

Compilation message

candies.cpp: In function 'std::vector<int> distribute_candies(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
candies.cpp:70:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   70 |         for(int j = 0; j < x[i].size(); j++)A.update(1, v[x[i][j]], x[i][j]+2, q+1, 1, q+1);
      |                        ~~^~~~~~~~~~~~~
candies.cpp:71:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |         for(int j = 0; j < y[i].size(); j++)A.update(1, -v[y[i][j]], y[i][j]+2, q+1, 1, q+1);
      |                        ~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 14428 KB Output is correct
2 Incorrect 2 ms 14428 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 345 ms 43000 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 14428 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 14428 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 14428 KB Output is correct
2 Incorrect 2 ms 14428 KB Output isn't correct
3 Halted 0 ms 0 KB -