-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDo Not Try This Problem.cpp
103 lines (93 loc) · 2.28 KB
/
Do Not Try This Problem.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include <bits/stdc++.h>
using namespace std;
#define all(foo) foo.begin(), foo.end()
#define sc(a) scanf("%d", &a)
#define sc2(a,b) scanf("%d%d", &a, &b)
#define sc3(a,b,c) scanf("%d%d%d", &a, &b, &c)
#define pri(x) printf("%d\n", x)
#define db(x) cerr << #x << " == " << x << endl
#define dbs(x) cerr << x << endl
#define x first
#define y second
typedef pair<int, int> ii;
const int magic = 113;
struct seg {
int n;
vector<pair<int, char>> t;
void build(string &v) {
n = v.size();
t.resize(n<<1, {1e9-1, 0});
for (int i = 0; i < n; i++) t[i+n].y = v[i];
}
void update(int l, int r, pair<int, char> value) {
for(l += n, r += n; l < r; l >>= 1, r >>= 1) {
if(l&1) t[l] = value, l++;
if(r&1) --r, t[r] = value;
}
}
void push() { // push modifications to leafs
for(int i = 1; i < n; i++) {
t[i<<1] = min(t[i], t[i<<1]);
t[i<<1|1] = min(t[i<<1|1], t[i]);
t[i] = {1e9, 0};
}
}
};
int main () {
ios::sync_with_stdio(0);
cin.tie(0);
string s;
cin >> s;
int n = s.size(), q;
cin >> q;
vector<vector<string>> v(magic);
vector<vector<vector<int>>> coord(magic);
vector<vector<seg>> tree(magic);
for (int i = 1; i < magic; i++) {
v[i].resize(i);
coord[i].resize(i);
tree[i].resize(i);
for (int j = 0; j < n; j++) {
v[i][j % i].push_back(s[j]);
coord[i][j % i].push_back(j);
}
for (int j = 0; j < i; j++) {
tree[i][j%i].build(v[i][j%i]);
}
v[i].clear();
}
vector<pair<int, char>> ans(n);
for (int i = 0; i < n; i++) {
ans[i] = {q, s[i]};
}
int i, a, k;
char c;
while (q--) {
cin >> i >> a >> k >> c;
i--;
if (a >= magic) {
int R = i+a*k;
for (int j = i; j <= R; j += a) {
ans[j] = {q, c};
}
} else {
int l = lower_bound(all(coord[a][i%a]), i) - coord[a][i%a].begin();
int r = upper_bound(all(coord[a][i%a]), i+k*a) - coord[a][i%a].begin();
tree[a][i%a].update(l, r, {q, c});
}
}
for (int i = 1; i < magic; i++) {
for (int j = 0; j < i; j++) {
tree[i][j].push();
int k = coord[i][j].size();
for (auto u : coord[i][j]) {
ans[u] = min(ans[u], tree[i][j].t[k]);
k++;
}
}
}
for (int i = 0; i < n; i++) {
s[i] = ans[i].y;
}
cout << s << endl;
}