Submission #876307

# Submission time Handle Problem Language Result Execution time Memory
876307 2023-11-21T14:18:30 Z Halfjuice Digital Circuit (IOI22_circuit) C++17
0 / 100
8 ms 2096 KB
#include <vector>
 
using namespace std;

long modPow(long b, long e, long m)
{
    b = b%m;
    long r = 1;
    while (e>0) {
        if (e%2 == 1) {
            r = (r*b) % m;
        }
        b = (b*b)%m;
        e >>= 1;
    }
    return r;
}

#define MOD 1000002022

typedef struct _Node {
    _Node* parent;
    vector<_Node*> children;
  
    int internalNodeCount;
    long contribCount;
  
    void initAny() {
        this->internalNodeCount = 0;
        this->contribCount = 0;
    
        for (auto it=children.begin(); it!=children.end(); it++) {
            (*it)->initAny();
            if ((*it)->children.size() > 0) {
                internalNodeCount += (*it)->internalNodeCount+1;
            }
        }
        internalNodeCount += 1;
    }
  
    long searchPathUp() {
        return (modPow(2, internalNodeCount, MOD) + parent->searchPathUp()) % MOD;
    }
  
    void initLeaf() {
        if (this->children.size() == 0) {
            contribCount = parent->searchPathUp();
        }
    }
} Node;
 
vector<Node> nodes;
vector<int> state;
long cur;
int n, m;
 
void init(int N, int M, vector<int> P, vector<int> A) {
    n = N;
    m = M;
    nodes.empty();
    for (int i=0; i<N+M; i++) {
        nodes.push_back(move(Node()));
        nodes[i].parent = &nodes[P[i]];
        nodes[P[i]].children.push_back(&nodes[i]);
    }
  
    for (int i=0; i<N+M; i++) {
        nodes[i].initAny();
    }
  
    for (int i=N; i<N+M; i++) {
        nodes[i].initLeaf();
    }
    
    state = A;
    cur = 0;
    for (int i=0; i<M; i++) {
        cur = (cur + nodes[N+i].contribCount*state[i]) % MOD;
    }
}
 
int count_ways(int L, int R) {
    for (int i=L; i<R; i++) {
        if (state[i]) {
            state[i] = 0;
            cur = (cur - nodes[n+i].contribCount) % MOD;
        } else {
            state[i] = 1;
            cur = (cur + nodes[n+i].contribCount) % MOD;
        }
    }
    if (cur < 0) {
        cur = cur + MOD;
    }
    return cur;
}

Compilation message

circuit.cpp: In function 'void init(int, int, std::vector<int>, std::vector<int>)':
circuit.cpp:60:16: warning: ignoring return value of 'bool std::vector<_Tp, _Alloc>::empty() const [with _Tp = _Node; _Alloc = std::allocator<_Node>]', declared with attribute 'nodiscard' [-Wunused-result]
   60 |     nodes.empty();
      |     ~~~~~~~~~~~^~
In file included from /usr/include/c++/10/vector:67,
                 from circuit.cpp:1:
/usr/include/c++/10/bits/stl_vector.h:1007:7: note: declared here
 1007 |       empty() const _GLIBCXX_NOEXCEPT
      |       ^~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 0 ms 344 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 344 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 0 ms 344 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 8 ms 2096 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 8 ms 2096 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 344 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 0 ms 344 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 0 ms 344 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -