답안 #231392

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
231392 2020-05-13T13:33:21 Z AlexLuchianov Sterilizing Spray (JOI15_sterilizing) C++14
100 / 100
265 ms 9516 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cassert>
#include <set>

using namespace std;

using ll = long long;
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) < (b)) ? (b) : (a))

int const nmax = 100000;
int v[1 + nmax];

class FenwickTree{
private:
  vector<ll> aib;
  int n;
public:
  FenwickTree(int n_ = 0){
    n = n_;
    aib.resize(1 + n);
  }
  void update(int pos, int val){
    for(int x = pos; x <= n; x += (x ^ (x & (x - 1))))
      aib[x] += val;
  }
  ll query(int pos){
    ll result = 0;
    for(int x = pos; 0 < x; x = (x & (x - 1)))
      result += aib[x];
    return result;
  }

  ll _query(int x, int y){
    ll result = query(y);
    if(0 < x)
      result -= query(x - 1);
    return result;
  }
};
FenwickTree aib;

set<int> myset;

void setvalue(int pos, int val){
  aib.update(pos, val - v[pos]);
  v[pos] = val;
  if(0 == v[pos])
    myset.erase(pos);
}

int main()
{
  ios::sync_with_stdio(0);
  cin.tie(0);

  int n, q, k;
  cin >> n >> q >> k;
  aib = FenwickTree(1 + n);
  for(int i = 1;i <= n; i++){
    int val;
    cin >> val;
    setvalue(i, val);
    myset.insert(i);
  }
  for(int i = 1;i <= q; i++){
    int op, x, y;
    cin >> op >> x >> y;
    if(op == 1){
      myset.insert(x);
      setvalue(x, y);
    } else if(op == 2){
      if(k == 1)
        continue;
      vector<int> targets;
      for(set<int>::iterator it = myset.lower_bound(x); it != myset.end() && *it <= y; it++)
        targets.push_back(*it);
      for(int i = 0; i < targets.size(); i++)
        setvalue(targets[i], v[targets[i]] / k);
    } else {
      cout << aib._query(x, y) << '\n';
    }
  }
  return 0;
}

Compilation message

sterilizing.cpp: In function 'int main()':
sterilizing.cpp:81:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
       for(int i = 0; i < targets.size(); i++)
                      ~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 6 ms 512 KB Output is correct
4 Correct 9 ms 512 KB Output is correct
5 Correct 9 ms 640 KB Output is correct
6 Correct 8 ms 640 KB Output is correct
7 Correct 9 ms 640 KB Output is correct
8 Correct 9 ms 640 KB Output is correct
9 Correct 9 ms 640 KB Output is correct
10 Correct 9 ms 640 KB Output is correct
11 Correct 9 ms 640 KB Output is correct
12 Correct 9 ms 640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 65 ms 5624 KB Output is correct
2 Correct 57 ms 4344 KB Output is correct
3 Correct 67 ms 6904 KB Output is correct
4 Correct 80 ms 8568 KB Output is correct
5 Correct 96 ms 9208 KB Output is correct
6 Correct 94 ms 9208 KB Output is correct
7 Correct 93 ms 9208 KB Output is correct
8 Correct 91 ms 9212 KB Output is correct
9 Correct 88 ms 9080 KB Output is correct
10 Correct 91 ms 9080 KB Output is correct
11 Correct 89 ms 9080 KB Output is correct
12 Correct 96 ms 9080 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 1280 KB Output is correct
2 Correct 31 ms 3328 KB Output is correct
3 Correct 35 ms 3584 KB Output is correct
4 Correct 50 ms 3192 KB Output is correct
5 Correct 95 ms 7908 KB Output is correct
6 Correct 98 ms 7800 KB Output is correct
7 Correct 91 ms 7800 KB Output is correct
8 Correct 92 ms 7928 KB Output is correct
9 Correct 86 ms 7780 KB Output is correct
10 Correct 84 ms 7652 KB Output is correct
11 Correct 85 ms 7652 KB Output is correct
12 Correct 91 ms 7652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 94 ms 5300 KB Output is correct
2 Correct 93 ms 5516 KB Output is correct
3 Correct 109 ms 4592 KB Output is correct
4 Correct 102 ms 4300 KB Output is correct
5 Correct 152 ms 9140 KB Output is correct
6 Correct 167 ms 9244 KB Output is correct
7 Correct 146 ms 9516 KB Output is correct
8 Correct 193 ms 9348 KB Output is correct
9 Correct 179 ms 8952 KB Output is correct
10 Correct 202 ms 9312 KB Output is correct
11 Correct 166 ms 8980 KB Output is correct
12 Correct 265 ms 9440 KB Output is correct