답안 #964045

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
964045 2024-04-16T08:54:20 Z LucaLucaM Sprinkler (JOI22_sprinkler) C++17
컴파일 오류
0 ms 0 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <cassert>
#include <cstring>
#include <queue>
#warning That's not AS, that's my AS

typedef long long ll;

const int NMAX = 2e5;

int L;

struct Node {
  int value, lazy;
};

struct segtree {
  std::vector<Node> aint;
  std::vector<int> brute;
  int n;
  segtree() {}
  segtree(int _n) {
    n = 1;
    while (n <= _n) {
      n <<= 1;
    }
    n <<= 1;
    n |= 1;
    aint.resize(n);
    for (int i = 0; i < n; i++) {
      aint[i] = {1, 1};
    }
    n = _n;
    brute.resize(n + 1, 1);
  }

  void push(int node, int tl, int tr) {
    if (aint[node].lazy != 1) {
      aint[node].value = (ll) aint[node].value * aint[node].lazy % L;
      if (tl != tr) {
        aint[2 * node].lazy = (ll) aint[node].lazy * aint[2 * node].lazy % L;
        aint[2 * node + 1].lazy = (ll) aint[node].lazy * aint[2 * node + 1].lazy % L;
      }
      aint[node].lazy = 1;
    }
  }
  void upd(int node, int tl, int tr, int l, int r, int v) {
    assert(1 <= tl && tl <= tr && tr <= n);
    push(node, tl, tr);
    if (l <= tl && tr <= r) {
      aint[node].lazy = v;
    } else {
      int mid = (tl + tr) / 2;
      if (l <= mid) {
        upd(2 * node, tl, mid, l, r, v);
      }
      if (mid < r) {
        upd(2 * node + 1, mid + 1, tr, l, r, v);
      }
      push(2 * node, tl, mid);
      push(2 * node + 1, mid + 1, tr);
      aint[node].value = (ll) aint[2 * node].value * aint[2 * node + 1].value;
    }
  }

  int qry(int node, int tl, int tr, int p) {
    push(node, tl, tr);
    if (tl == tr) {
      return aint[node].value;
    } else {
      int mid = (tl + tr) / 2;
      if (p <= mid) {
        return qry(2 * node, tl, mid, p);
      }
      return qry(2 * node + 1, mid + 1, tr, p);
    }
  }

  void bruteUpdate(int l, int r, int v) {
    for (int i = l; i <= r; i++) {
      brute[i] = (ll) brute[i] * v % L;
    }
  }
  int bruteQuery(int p) {
    return brute[p];
  }

  void update(int l, int r, int v) {
//    bruteUpdate(l, r, v);
    upd(1, 1, n, l, r, v);
  }
  int query(int p) {
//    return bruteQuery(p);
    return qry(1, 1, n, p);
  }
};

std::vector<int> g[NMAX + 1];
int parent[NMAX + 1];
int time[NMAX + 1];
int timer;

void bfs() {
  std::queue<int> q;
  q.push(1);
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    time[u] = ++timer;
    std::vector<int> newG;
    for (const auto &v : g[u]) {
      if (!time[v]) {
        parent[v] = u;
        newG.push_back(v);
        q.push(v);
      }
    }
    g[u] = newG;
  }
}

int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(0);

  int n;
  std::cin >> n >> L;

  for (int i = 1; i < n; i++) {
    int u, v;
    std::cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }

  bfs();

//  std::cout << " > ";
//  for (int i = 1; i <= n; i++) {
//    std::cout << time[i] << ' ';
//  }
//  std::cout << '\n';

  segtree aint(2 * n + 1);

  for (int i = 1; i <= n; i++) {
    int h;
    std::cin >> h;
    aint.update(time[i], time[i], h);
  }

  int q;
  std::cin >> q;

  while (q--) {
    int type;
    std::cin >> type;
    if (type == 1) {
      int u, d, h;
      std::cin >> u >> d >> h;
      assert(d <= 1);
      aint.update(time[u], time[u], h);
      if (d == 1) {
        if (!g[u].empty()) {
          int l = time[g[u][0]];
          int r = time[g[u].back()];
          aint.update(l, r, h);
        }
        if (u != 1) {
          int v = parent[u];
          aint.update(time[v], time[v], h);
        }
      }
    } else {
      int u;
      std::cin >> u;
      std::cout << aint.query(time[u]) << '\n';
    }
  }

  return 0;
}

Compilation message

sprinkler.cpp:7:2: warning: #warning That's not AS, that's my AS [-Wcpp]
    7 | #warning That's not AS, that's my AS
      |  ^~~~~~~
sprinkler.cpp:102:18: error: 'int time [200001]' redeclared as different kind of entity
  102 | int time[NMAX + 1];
      |                  ^
In file included from /usr/include/pthread.h:23,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/gthr-default.h:35,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/gthr.h:148,
                 from /usr/include/c++/10/ext/atomicity.h:35,
                 from /usr/include/c++/10/bits/ios_base.h:39,
                 from /usr/include/c++/10/ios:42,
                 from /usr/include/c++/10/ostream:38,
                 from /usr/include/c++/10/iostream:39,
                 from sprinkler.cpp:1:
/usr/include/time.h:75:15: note: previous declaration 'time_t time(time_t*)'
   75 | extern time_t time (time_t *__timer) __THROW;
      |               ^~~~
sprinkler.cpp: In function 'void bfs()':
sprinkler.cpp:111:11: warning: pointer to a function used in arithmetic [-Wpointer-arith]
  111 |     time[u] = ++timer;
      |           ^
sprinkler.cpp:111:13: error: assignment of read-only location '*(time + ((sizetype)u))'
  111 |     time[u] = ++timer;
      |     ~~~~~~~~^~~~~~~~~
sprinkler.cpp:114:18: warning: pointer to a function used in arithmetic [-Wpointer-arith]
  114 |       if (!time[v]) {
      |                  ^
sprinkler.cpp: In function 'int main()':
sprinkler.cpp:151:23: warning: pointer to a function used in arithmetic [-Wpointer-arith]
  151 |     aint.update(time[i], time[i], h);
      |                       ^
sprinkler.cpp:151:32: warning: pointer to a function used in arithmetic [-Wpointer-arith]
  151 |     aint.update(time[i], time[i], h);
      |                                ^
sprinkler.cpp:151:23: error: invalid conversion from 'time_t (*)(time_t*) noexcept' {aka 'long int (*)(long int*) noexcept'} to 'int' [-fpermissive]
  151 |     aint.update(time[i], time[i], h);
      |                 ~~~~~~^
      |                       |
      |                       time_t (*)(time_t*) noexcept {aka long int (*)(long int*) noexcept}
sprinkler.cpp:90:19: note:   initializing argument 1 of 'void segtree::update(int, int, int)'
   90 |   void update(int l, int r, int v) {
      |               ~~~~^
sprinkler.cpp:151:32: error: invalid conversion from 'time_t (*)(time_t*) noexcept' {aka 'long int (*)(long int*) noexcept'} to 'int' [-fpermissive]
  151 |     aint.update(time[i], time[i], h);
      |                          ~~~~~~^
      |                                |
      |                                time_t (*)(time_t*) noexcept {aka long int (*)(long int*) noexcept}
sprinkler.cpp:90:26: note:   initializing argument 2 of 'void segtree::update(int, int, int)'
   90 |   void update(int l, int r, int v) {
      |                      ~~~~^
sprinkler.cpp:164:25: warning: pointer to a function used in arithmetic [-Wpointer-arith]
  164 |       aint.update(time[u], time[u], h);
      |                         ^
sprinkler.cpp:164:34: warning: pointer to a function used in arithmetic [-Wpointer-arith]
  164 |       aint.update(time[u], time[u], h);
      |                                  ^
sprinkler.cpp:164:25: error: invalid conversion from 'time_t (*)(time_t*) noexcept' {aka 'long int (*)(long int*) noexcept'} to 'int' [-fpermissive]
  164 |       aint.update(time[u], time[u], h);
      |                   ~~~~~~^
      |                         |
      |                         time_t (*)(time_t*) noexcept {aka long int (*)(long int*) noexcept}
sprinkler.cpp:90:19: note:   initializing argument 1 of 'void segtree::update(int, int, int)'
   90 |   void update(int l, int r, int v) {
      |               ~~~~^
sprinkler.cpp:164:34: error: invalid conversion from 'time_t (*)(time_t*) noexcept' {aka 'long int (*)(long int*) noexcept'} to 'int' [-fpermissive]
  164 |       aint.update(time[u], time[u], h);
      |                            ~~~~~~^
      |                                  |
      |                                  time_t (*)(time_t*) noexcept {aka long int (*)(long int*) noexcept}
sprinkler.cpp:90:26: note:   initializing argument 2 of 'void segtree::update(int, int, int)'
   90 |   void update(int l, int r, int v) {
      |                      ~~~~^
sprinkler.cpp:167:31: warning: pointer to a function used in arithmetic [-Wpointer-arith]
  167 |           int l = time[g[u][0]];
      |                               ^
sprinkler.cpp:167:31: error: invalid conversion from 'time_t (*)(time_t*) noexcept' {aka 'long int (*)(long int*) noexcept'} to 'int' [-fpermissive]
sprinkler.cpp:168:35: warning: pointer to a function used in arithmetic [-Wpointer-arith]
  168 |           int r = time[g[u].back()];
      |                                   ^
sprinkler.cpp:168:35: error: invalid conversion from 'time_t (*)(time_t*) noexcept' {aka 'long int (*)(long int*) noexcept'} to 'int' [-fpermissive]
sprinkler.cpp:173:29: warning: pointer to a function used in arithmetic [-Wpointer-arith]
  173 |           aint.update(time[v], time[v], h);
      |                             ^
sprinkler.cpp:173:38: warning: pointer to a function used in arithmetic [-Wpointer-arith]
  173 |           aint.update(time[v], time[v], h);
      |                                      ^
sprinkler.cpp:173:29: error: invalid conversion from 'time_t (*)(time_t*) noexcept' {aka 'long int (*)(long int*) noexcept'} to 'int' [-fpermissive]
  173 |           aint.update(time[v], time[v], h);
      |                       ~~~~~~^
      |                             |
      |                             time_t (*)(time_t*) noexcept {aka long int (*)(long int*) noexcept}
sprinkler.cpp:90:19: note:   initializing argument 1 of 'void segtree::update(int, int, int)'
   90 |   void update(int l, int r, int v) {
      |               ~~~~^
sprinkler.cpp:173:38: error: invalid conversion from 'time_t (*)(time_t*) noexcept' {aka 'long int (*)(long int*) noexcept'} to 'int' [-fpermissive]
  173 |           aint.update(time[v], time[v], h);
      |                                ~~~~~~^
      |                                      |
      |                                      time_t (*)(time_t*) noexcept {aka long int (*)(long int*) noexcept}
sprinkler.cpp:90:26: note:   initializing argument 2 of 'void segtree::update(int, int, int)'
   90 |   void update(int l, int r, int v) {
      |                      ~~~~^
sprinkler.cpp:179:37: warning: pointer to a function used in arithmetic [-Wpointer-arith]
  179 |       std::cout << aint.query(time[u]) << '\n';
      |                                     ^
sprinkler.cpp:179:37: error: invalid conversion from 'time_t (*)(time_t*) noexcept' {aka 'long int (*)(long int*) noexcept'} to 'int' [-fpermissive]
  179 |       std::cout << aint.query(time[u]) << '\n';
      |                               ~~~~~~^
      |                                     |
      |                                     time_t (*)(time_t*) noexcept {aka long int (*)(long int*) noexcept}
sprinkler.cpp:94:17: note:   initializing argument 1 of 'int segtree::query(int)'
   94 |   int query(int p) {
      |             ~~~~^