답안 #623460

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
623460 2022-08-05T15:56:27 Z truc12a2cvp 사탕 분배 (IOI21_candies) C++17
27 / 100
312 ms 23868 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> II;
const int N = 2e5 + 5, logN = 20;
const int MOD = 1e9 + 7;
const ll INF = 1e9;

struct F{
       int L, R, sum;
       F(int _L = 0, int _R = 0, int _sum = 0) : L(_L), R(_R), sum(_sum) {}
       F operator + (const F& op) const{
              return F(max(op.L, min(op.R, L + op.sum)),
                       max(op.L, min(op.R, R + op.sum)),
                       sum + op.sum);
       }
};

int C;

struct ST_lazy{
       int n;
       vector<F> ST;
       ST_lazy(int _n = 0){
              n = _n;
              ST.resize(4 * n + 5);
       }
       void down(int id, int l, int r){
              if(l == r) return;
              ST[id * 2] = ST[id * 2] + ST[id];
              ST[id * 2 + 1] = ST[id * 2 + 1] + ST[id];
              ST[id] = F(0, C, 0);
       }
       void update(int id, int l, int r, int u, int v, int add){
              down(id, l, r);
              if(r < u || v < l) return;
              if(u <= l && r <= v){
                     ST[id] = ST[id] + F(0, C, add);
                     return;
              }
              int mid = l + r >> 1;
              update(id * 2, l, mid, u, v, add);
              update(id * 2 + 1, mid + 1, r, u, v, add);
       }
       int get(int id, int l, int r, int i){
              down(id, l, r);
              if(l == r) return max(ST[id].L, min(ST[id].R, ST[id].sum));
              int mid = l + r >> 1;
              if(i <= mid) return get(id * 2, l, mid, i);
              return get(id * 2 + 1, mid + 1, r, i);
       }
};

vector<int> distribute_candies(vector<int> c, vector<int> l, vector<int> r, vector<int> v){
       int n = c.size(), q = l.size();
       ST_lazy ST(n);
       C = c[0];
       for(int i = 0; i < q; i ++){
              ST.update(1, 1, n, l[i] + 1, r[i] + 1, v[i]);
       }
       vector<int> ans;
       for(int i = 1; i <= n; i ++) ans.push_back(ST.get(1, 1, n, i));
       return ans;
}

Compilation message

candies.cpp: In member function 'void ST_lazy::update(int, int, int, int, int, int)':
candies.cpp:41:27: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   41 |               int mid = l + r >> 1;
      |                         ~~^~~
candies.cpp: In member function 'int ST_lazy::get(int, int, int, int)':
candies.cpp:48:27: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   48 |               int mid = l + r >> 1;
      |                         ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 312 ms 21960 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 129 ms 8024 KB Output is correct
3 Correct 88 ms 14584 KB Output is correct
4 Correct 302 ms 23024 KB Output is correct
5 Correct 303 ms 23420 KB Output is correct
6 Correct 302 ms 23868 KB Output is correct
7 Correct 298 ms 23124 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -