이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <vector>
#include <iostream>
#include <cassert>
#include <cmath>
#include <map>
using namespace std;
struct SegmentTree {
vector<int> vec;
const int id = 0;
int merge (int x, int y) {
return x + y;
}
void update (int x, int y) {
x += (int)vec.size()/2 - 1;
vec[x] = y;
while (x != 0) {
x = (x - 1)/2;
vec[x] = merge(vec[2 * x + 1], vec[2 * x + 2]);
}
}
int query (int dum, int tl, int tr, int l, int r) {
if (tl >= l and tr <= r) {
return vec[dum];
}
if (tl > r or tr < l) {
return id;
}
return merge(query(2 * dum + 1, tl, (tl + tr)/2, l, r), query(2 * dum + 2, (tl + tr)/2 + 1, tr, l, r));
}
int query (int l, int r) {
return query(0, 0, (int)vec.size()/2 - 1, l, r);
}
SegmentTree (int n) {
n = (1 << ((int)log2(n) + 1));
vec.assign(2 * n, 0);
}
};
int main () {
int N, Q;
cin >> N >> Q;
vector<vector<int>> queries;
vector<bool> ans;
ans.assign(Q, false);
while (Q--) {
char c;
cin >> c;
if (c == 'C') {
int x, y;
cin >> x >> y;
queries.push_back({--x, --y});
} else {
int x; cin >> x;
queries.push_back({--x});
}
}
vector<bool> act;
for (int i = 2; i <= N; i++) {
act.assign(N, false);
SegmentTree st(N);
for (int j = 0; j < queries.size(); j++) {
auto q = queries[j];
if (q.size() == 1) {
if ((q[0] + 1) % i == 0) {
if (!act[q[0]]) {
st.update(q[0], 1);
} else {
st.update(q[0], 0);
}
act[q[0]] = not act[q[0]];
}
} else {
int l = q[0], r = q[1];
if (st.query(l, r) >= 2) {
ans[j] = true;
}
}
}
}
for (int i = 0; i < queries.size(); i++) {
if (queries[i].size() == 2) {
cout << (ans[i] ? "DA" : "NE") << '\n';
}
}
}
컴파일 시 표준 에러 (stderr) 메시지
Main.cpp: In function 'int main()':
Main.cpp:60:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
60 | for (int j = 0; j < queries.size(); j++) {
| ~~^~~~~~~~~~~~~~~~
Main.cpp:79:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
79 | for (int i = 0; i < queries.size(); i++) {
| ~~^~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |