QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#952138 | #8471. Lines on a Phone Screen | elecball | WA | 1ms | 3584kb | C++17 | 3.3kb | 2025-03-26 20:12:52 | 2025-03-26 20:12:54 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
struct node {
vector<pii> V; // line, rest
node() { V.resize(24); }
void make_leaf(int a) {
for (int i = 0; i < 24; i++) {
if (a+i < 24) V[i] = make_pair(0, a+i);
else V[i] = make_pair(1, a);
}
}
};
node zero_node;
vector<pii> comb_v(vector<pii> v1, vector<pii> v2) {
vector<pii> V(24);
for (int i = 0; i < 24; i++) {
int line1 = v1[i].first, rest1 = v1[i].second;
int line2 = v2[rest1].first, rest2 = v2[rest1].second;
V[i] = make_pair(line1 + line2, rest2);
}
return V;
}
vector<node> seg_tree;
void update(int n, int start, int end, int x, int c) {
if (start == end) {
seg_tree[n].make_leaf(c);
// cout << n << " " << start << " : \n";
// for (int i = 0; i < 24; i++) {
// cout << i << " : " << seg_tree[n].V[i].first << ", " << seg_tree[n].V[i].second << " / ";
// }
// cout << "\n";
return;
}
int mid = (start + end) / 2;
if (x <= mid) update(2*n, start, mid, x, c);
else update(2*n+1, mid+1, end, x, c);
seg_tree[n].V = comb_v(seg_tree[2*n].V, seg_tree[2*n+1].V);
// cout << n << " " << start << " " << end << " : \n";
// for (int i = 0; i < 24; i++) {
// cout << i << " : " << seg_tree[n].V[i].first << ", " << seg_tree[n].V[i].second << " / ";
// }
// cout << "\n";
}
vector<pii> query(int n, int start, int end, int left, int right) {
if (right < start || end < left) return zero_node.V;
if (left <= start && end <= right) {
// cout << n << " " << start << "-" << end << " " << left << "-" << right << " : \n";
// for (int i = 0; i < 24; i++) {
// cout << i << " : " << seg_tree[n].V[i].first << ", " << seg_tree[n].V[i].second << " / ";
// }
// cout << "\n";
return seg_tree[n].V;
}
int mid = (start + end) / 2;
vector<pii> res = comb_v(query(2*n, start, mid, left, right), query(2*n+1, mid+1, end, left, right));
// cout << n << " " << start << "-" << end << " " << left << "-" << right << " : \n";
// for (int i = 0; i <= 24; i++) {
// cout << i << " : " << res[i].first << ", " << res[i].second << " / ";
// }
// cout << "\n";
return res;
}
int main() {
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
zero_node.make_leaf(0);
int N, M;
cin >> N >> M;
seg_tree.resize(4 * (N+2), node());
// cout << "zero\n";
// for (int i = 0; i < 24; i++) {
// cout << i << " : " << zero_node.V[i].first << ", " << zero_node.V[i].second << " / ";
// }
// cout << "\n";
int a;
for (int x = 1; x <= N; x++) {
cin >> a;
update(1, 1, N, x, a);
}
while (M--) {
int op;
cin >> op;
if (op == 1) {
int x, c;
cin >> x >> c;
update(1, 1, N, x, c);
}
else {
int l, r;
cin >> l >> r;
vector<pii> q = query(1, 1, N, l, r);
cout << q[0].first + (q[0].second != 0) << "\n";
}
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3584kb
input:
5 5 8 8 9 12 13 2 1 5 2 2 4 1 5 3 2 1 5 2 2 5
output:
3 2 3 2
result:
wrong answer 3rd numbers differ - expected: '2', found: '3'