mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-09 15:58:47 +00:00
Compare commits
2 Commits
130b828bf1
...
ecea56b0ac
Author | SHA1 | Date | |
---|---|---|---|
ecea56b0ac | |||
89afe5ac91 |
126
BZOJ/1901/1901.cpp
Normal file
126
BZOJ/1901/1901.cpp
Normal file
@ -0,0 +1,126 @@
|
||||
#include <iostream>
|
||||
#include <cstring>
|
||||
#include <tuple>
|
||||
#include <vector>
|
||||
|
||||
using std::cin;
|
||||
using std::cout;
|
||||
const char endl = '\n';
|
||||
|
||||
const int N = 1e5 + 5;
|
||||
|
||||
int n, m, a[N], c[N], ans[N];
|
||||
|
||||
inline int lowbit(int x) {
|
||||
return x & -x;
|
||||
}
|
||||
|
||||
inline void add(int x, int y) {
|
||||
for (; x <= n; x += lowbit(x)) c[x] += y;
|
||||
}
|
||||
|
||||
inline int sum(int x) {
|
||||
int ret = 0;
|
||||
for (; x > 0; x -= lowbit(x)) ret += c[x];
|
||||
return ret;
|
||||
}
|
||||
|
||||
void solve(int l, int r, const std::vector<std::tuple<char, int, int, int, int>>& q) {
|
||||
if (q.empty()) return;
|
||||
|
||||
if (r - l == 1) {
|
||||
for (const auto& x : q) {
|
||||
if (std::get<0>(x) == 'Q') {
|
||||
ans[std::get<4>(x)] = l;
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
int mid = l + r >> 1;
|
||||
std::vector<std::tuple<char, int, int, int, int>> left, right;
|
||||
|
||||
for (const auto& e : q) {
|
||||
char op;
|
||||
int x, y, z, id;
|
||||
|
||||
std::tie(op, x, y, z, id) = e;
|
||||
|
||||
if (op == 'Q') {
|
||||
int k = sum(y) - sum(x - 1);
|
||||
|
||||
if (k >= z) {
|
||||
left.push_back(e);
|
||||
} else {
|
||||
z -= k;
|
||||
right.emplace_back(op, x, y, z, id);
|
||||
}
|
||||
} else { // op == 'C'
|
||||
if (y < mid) {
|
||||
add(x, z);
|
||||
left.push_back(e);
|
||||
} else {
|
||||
right.push_back(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (const auto& e : left) {
|
||||
char op;
|
||||
int x, y, z, id;
|
||||
|
||||
std::tie(op, x, y, z, id) = e;
|
||||
|
||||
if (op == 'C') {
|
||||
add(x, -z);
|
||||
}
|
||||
}
|
||||
|
||||
solve(l, mid, left);
|
||||
solve(mid, r, right);
|
||||
}
|
||||
|
||||
int main() {
|
||||
std::ios::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
|
||||
memset(ans, 0xff, sizeof(ans));
|
||||
|
||||
cin >> n >> m;
|
||||
|
||||
std::vector<std::tuple<char, int, int, int, int>> q;
|
||||
|
||||
for (int i = 1; i <= n; i++) {
|
||||
cin >> a[i];
|
||||
|
||||
q.emplace_back('C', i, a[i], 1, 0);
|
||||
}
|
||||
|
||||
for (int i = 1; i <= m; i++) {
|
||||
char op;
|
||||
int x, y, z;
|
||||
|
||||
cin >> op >> x >> y;
|
||||
|
||||
if (op == 'Q') {
|
||||
cin >> z;
|
||||
|
||||
q.emplace_back('Q', x, y, z, i);
|
||||
} else { // op == 'C'
|
||||
q.emplace_back('C', x, a[x], -1, 0);
|
||||
a[x] = y;
|
||||
q.emplace_back('C', x, y, 1, 0);
|
||||
}
|
||||
}
|
||||
|
||||
solve(0, 1e9, q);
|
||||
|
||||
for (int i = 1; i <= m; i++) {
|
||||
if (~ans[i]) {
|
||||
cout << ans[i] << endl;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
BIN
BZOJ/1901/data/1.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/1901/data/1.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1901/data/1.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/1901/data/1.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1901/data/10.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/1901/data/10.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1901/data/10.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/1901/data/10.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1901/data/2.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/1901/data/2.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1901/data/2.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/1901/data/2.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1901/data/3.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/1901/data/3.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1901/data/3.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/1901/data/3.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1901/data/4.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/1901/data/4.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1901/data/4.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/1901/data/4.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1901/data/5.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/1901/data/5.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1901/data/5.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/1901/data/5.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1901/data/6.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/1901/data/6.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1901/data/6.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/1901/data/6.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1901/data/7.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/1901/data/7.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1901/data/7.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/1901/data/7.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1901/data/8.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/1901/data/8.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1901/data/8.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/1901/data/8.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1901/data/9.in
(Stored with Git LFS)
Normal file
BIN
BZOJ/1901/data/9.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
BZOJ/1901/data/9.out
(Stored with Git LFS)
Normal file
BIN
BZOJ/1901/data/9.out
(Stored with Git LFS)
Normal file
Binary file not shown.
126
Luogu/P2617/P2617.cpp
Normal file
126
Luogu/P2617/P2617.cpp
Normal file
@ -0,0 +1,126 @@
|
||||
#include <iostream>
|
||||
#include <cstring>
|
||||
#include <tuple>
|
||||
#include <vector>
|
||||
|
||||
using std::cin;
|
||||
using std::cout;
|
||||
const char endl = '\n';
|
||||
|
||||
const int N = 1e5 + 5;
|
||||
|
||||
int n, m, a[N], c[N], ans[N];
|
||||
|
||||
inline int lowbit(int x) {
|
||||
return x & -x;
|
||||
}
|
||||
|
||||
inline void add(int x, int y) {
|
||||
for (; x <= n; x += lowbit(x)) c[x] += y;
|
||||
}
|
||||
|
||||
inline int sum(int x) {
|
||||
int ret = 0;
|
||||
for (; x > 0; x -= lowbit(x)) ret += c[x];
|
||||
return ret;
|
||||
}
|
||||
|
||||
void solve(int l, int r, const std::vector<std::tuple<char, int, int, int, int>>& q) {
|
||||
if (q.empty()) return;
|
||||
|
||||
if (r - l == 1) {
|
||||
for (const auto& x : q) {
|
||||
if (std::get<0>(x) == 'Q') {
|
||||
ans[std::get<4>(x)] = l;
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
int mid = l + r >> 1;
|
||||
std::vector<std::tuple<char, int, int, int, int>> left, right;
|
||||
|
||||
for (const auto& e : q) {
|
||||
char op;
|
||||
int x, y, z, id;
|
||||
|
||||
std::tie(op, x, y, z, id) = e;
|
||||
|
||||
if (op == 'Q') {
|
||||
int k = sum(y) - sum(x - 1);
|
||||
|
||||
if (k >= z) {
|
||||
left.push_back(e);
|
||||
} else {
|
||||
z -= k;
|
||||
right.emplace_back(op, x, y, z, id);
|
||||
}
|
||||
} else { // op == 'C'
|
||||
if (y < mid) {
|
||||
add(x, z);
|
||||
left.push_back(e);
|
||||
} else {
|
||||
right.push_back(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (const auto& e : left) {
|
||||
char op;
|
||||
int x, y, z, id;
|
||||
|
||||
std::tie(op, x, y, z, id) = e;
|
||||
|
||||
if (op == 'C') {
|
||||
add(x, -z);
|
||||
}
|
||||
}
|
||||
|
||||
solve(l, mid, left);
|
||||
solve(mid, r, right);
|
||||
}
|
||||
|
||||
int main() {
|
||||
std::ios::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
|
||||
memset(ans, 0xff, sizeof(ans));
|
||||
|
||||
cin >> n >> m;
|
||||
|
||||
std::vector<std::tuple<char, int, int, int, int>> q;
|
||||
|
||||
for (int i = 1; i <= n; i++) {
|
||||
cin >> a[i];
|
||||
|
||||
q.emplace_back('C', i, a[i], 1, 0);
|
||||
}
|
||||
|
||||
for (int i = 1; i <= m; i++) {
|
||||
char op;
|
||||
int x, y, z;
|
||||
|
||||
cin >> op >> x >> y;
|
||||
|
||||
if (op == 'Q') {
|
||||
cin >> z;
|
||||
|
||||
q.emplace_back('Q', x, y, z, i);
|
||||
} else { // op == 'C'
|
||||
q.emplace_back('C', x, a[x], -1, 0);
|
||||
a[x] = y;
|
||||
q.emplace_back('C', x, y, 1, 0);
|
||||
}
|
||||
}
|
||||
|
||||
solve(0, 1e9, q);
|
||||
|
||||
for (int i = 1; i <= m; i++) {
|
||||
if (~ans[i]) {
|
||||
cout << ans[i] << endl;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user