Skip to content

Commit ea5683e

Browse files
committed
updated debugger
1 parent d51deb0 commit ea5683e

File tree

3 files changed

+55
-98
lines changed

3 files changed

+55
-98
lines changed

code.cpp

Lines changed: 35 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -11,116 +11,56 @@
1111
using namespace std;
1212

1313
using ll = long long;
14+
using lll = __int128_t;
1415
using ld = long double;
1516
using ull = unsigned long long;
1617
template <typename T>
1718
using minHeap = priority_queue<T, vector<T>, greater<T>>;
1819

19-
const ld PI = acos(-1.0);
20-
const ll MOD = 1e9 + 7;
21-
const ld EPS = 1e-9;
22-
const ll N = 4e5 + 5; //
23-
int tc = 1;
24-
2520
#ifdef LOCAL
2621
#include "debug.h"
2722
#else
2823
#define debug(...)
2924
#endif
3025

31-
#define left (node * 2)
32-
#define right (left + 1)
33-
34-
ll n, tree[4 * N], cnt[4 * N], sorted[N];
35-
36-
void build(int node, int lo, int hi) {
37-
tree[node] = 0;
38-
cnt[node] = 0;
39-
if (lo == hi) return;
40-
ll mid = (lo + hi) >> 1;
41-
build(left, lo, mid);
42-
build(right, mid + 1, hi);
43-
}
44-
45-
void update(int node, int lo, int hi, int i, int val) {
46-
47-
if (i > hi or i < lo) return;
48-
if (i <= lo and hi <= i) {
49-
cnt[node] = 1;
50-
tree[node] = val;
51-
return;
52-
}
53-
54-
ll mid = (lo + hi) >> 1;
55-
update(left, lo, mid, i, val);
56-
update(right, mid + 1, hi, i, val);
57-
cnt[node] = cnt[left] + cnt[right];
58-
tree[node] = tree[left] + tree[right];
59-
}
60-
61-
pair<ll, int> query(int node, int lo, int hi, int L, int R) {
62-
if (L > hi or R < lo) return {0LL, 0};
63-
if (L <= lo and hi <= R) return {tree[node], cnt[node]};
64-
ll mid = (lo + hi) >> 1;
65-
auto leftQuery = query(left, lo, mid, L, R);
66-
auto rightQuery = query(right, mid + 1, hi, L, R);
67-
leftQuery.first += rightQuery.first;
68-
leftQuery.second += rightQuery.second;
69-
return leftQuery;
70-
}
71-
72-
bool check(ll a, ll b, ll mid) {
73-
auto p = query(1, 1, n, 1, mid);
74-
return (a * (p.second + 1)) >= (p.first + b);
75-
// min(a1,a2,a2...am) * m >= (b1+b2+b3..+bm)
76-
}
77-
78-
ll BS(int a, int b) {
79-
ll lo = 1, hi = n, res = -1;
80-
while (lo <= hi) {
81-
ll mid = (lo + hi) / 2;
82-
if (check(a, b, mid)) {
83-
lo = mid + 1;
84-
res = mid;
85-
} else {
86-
hi = mid - 1;
87-
}
88-
}
89-
if (res == -1) return 0;
90-
return query(1, 1, n, 1, res).second + 1;
26+
const ld PI = acos(-1.0);
27+
const ll MOD = 1e9 + 7;
28+
const ld EPS = 1e-9;
29+
const int N = 2e5 + 5;
30+
int tc = 1;
31+
bool isValid(string &s, int i) {
32+
return i >= 0 && i + 3 < sz(s) && s.substr(i, 4) == "1100";
9133
}
92-
93-
9434
void solve() {
95-
cin >> n;
96-
pair<int, int> a[n + 1];
97-
vector < pair<int, int>> b(n + 1);
98-
for (int i = 1; i <= n; i++) {
99-
cin >> a[i].first >> a[i].second;
100-
}
101-
sort(a + 1, a + n + 1);
102-
for (int i = 1 ; i <= n; i++) {
103-
b[i].first = a[i].second;
104-
b[i].second = i;
105-
}
106-
sort(all(b));
107-
108-
for (int i = 1; i <= n; i++) {
109-
sorted[b[i].second] = i;
35+
string s;
36+
int q;
37+
cin >> s >> q;
38+
int ans = 0, n = sz(s);
39+
vector<bool> flag(n + 1, false);
40+
for (int i = 0; i + 3 < n; ++i) {
41+
if (isValid(s, i)) {
42+
flag[i] = true;
43+
ans++;
44+
}
11045
}
111-
// for (int i = 1; i <= n; i++) {
112-
// cout << sorted[i] << ' ';
113-
// }
114-
// cout << '\n';
115-
build(1, 1, n);
116-
ll ans = 0;
117-
for (int i = n; i >= 1; i--) {
118-
int idx = sorted[i];
119-
ll MaxWithFixedMin = BS(a[i].first, a[i].second);
120-
ans = max(ans, MaxWithFixedMin);
121-
update(1, 1, n, idx, a[i].second);
46+
while (q--) {
47+
int pos, val;
48+
cin >> pos >> val;
49+
pos--;
50+
if (s[pos] == char(val)) {
51+
cout << (ans > 0 ? "YES" : "NO") << '\n';
52+
continue;
53+
}
54+
s[pos] = '0' + val;
55+
for (int i = pos - 3; i <= pos; ++i) {
56+
if (i >= 0 && i + 3 < sz(s)) {
57+
if (flag[i]) ans--;
58+
flag[i] = isValid(s, i);
59+
if (flag[i]) ans++;
60+
}
61+
}
62+
cout << (ans > 0 ? "YES" : "NO") << '\n';
12263
}
123-
cout << ans << '\n';
12464
}
12565

12666
int main() {

debug.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ ostream& operator<<(ostream &out, const stack<T>& S) {
7373
return out;
7474
}
7575
stack<T> st = S;
76-
out << "<";
76+
out << "[";
7777
while ((int)st.size() > 1) {
7878
out << st.top() << ", ";
7979
st.pop();

sol.cpp

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,32 @@ const ld EPS = 1e-9;
2929
const int N = 2e5 + 5;
3030
int tc = 1;
3131

32-
void solve() {
32+
int n, a[N], Left[N], right[N];
3333

34+
void solve() {
35+
cin >> n;
36+
for (int i = 1; i <= n; i++) cin >> a[i];
37+
stack<int> leftStack, rightStack;
38+
39+
leftStack.push(0);
40+
for (int i = 1; i <= n; i ++) {
41+
while (!leftStack.empty() and a[leftStack.top()] >= a[i]) {
42+
leftStack.pop();
43+
}
44+
debug(leftStack);
45+
Left[i] = leftStack.top();
46+
leftStack.push(i);
47+
}
48+
for (int i = 1; i <= n; i++) {
49+
cout << Left[i] << ' ';
50+
}
3451
}
3552

3653
int main() {
3754
unsyncIO;
3855

3956
int t = 1;
40-
//cin >> t;
57+
cin >> t;
4158
while (t--) {
4259
solve();
4360
}

0 commit comments

Comments
 (0)