Hi!
We all know how important it is to choose a university.
But I have a problem with that.
please help me with choosing a university!
# | User | Rating |
---|---|---|
1 | tourist | 3690 |
2 | jiangly | 3647 |
3 | Benq | 3581 |
4 | orzdevinwang | 3570 |
5 | Geothermal | 3569 |
5 | cnnfls_csy | 3569 |
7 | Radewoosh | 3509 |
8 | ecnerwala | 3486 |
9 | jqdai0815 | 3474 |
10 | gyh20 | 3447 |
# | User | Contrib. |
---|---|---|
1 | maomao90 | 174 |
2 | awoo | 165 |
3 | adamant | 161 |
4 | TheScrasse | 160 |
5 | nor | 158 |
6 | maroonrk | 156 |
7 | -is-this-fft- | 152 |
8 | orz | 146 |
9 | SecondThread | 145 |
9 | pajenegod | 145 |
Hi!
We all know how important it is to choose a university.
But I have a problem with that.
please help me with choosing a university!
how many words per minute you type?
Hello everybody!
#include<bits/stdc++.h>
#define ll long long
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
struct seg {
vector<vector<int>> tree;
int size;
void init(int n) {
size = 1;
while (size < n)size *= 2;
for (int i = 0; i < 2 * size; ++i)tree.push_back({0});
}
vector<int> combine(vector<int> a, vector<int> b) {
for (auto i: b)if (i != 0)a.push_back(i);
sort(a.begin(), a.end());
return a;
}
void set(int i, int v, int x, int lx, int rx) {
if (rx - lx == 1) {
tree[x].pop_back();
tree[x].push_back(v);
return;
}
int mid = (lx + rx) >> 1;
if (i < mid)set(i, v, 2 * x + 1, lx, mid);
else set(i, v, 2 * x + 2, mid, rx);
tree[x] = combine(tree[2 * x + 1], tree[2 * x + 2]);
}
void set(int i, int v) {
set(i, v, 0, 0, size);
}
vector<int> get(int l, int r, int x, int lx, int rx) {
if (l >= rx || lx >= r)return {0};
if (lx >= l && rx <= r) {
return tree[x];
}
int mid = (lx + rx) >> 1;
return combine(get(l, r, 2 * x + 1, lx, mid), get(l, r, 2 * x + 2, mid, rx));
}
vector<int> get(int l, int r) {
return get(l, r, 0, 0, size);
}
};
int32_t main() {
fast
int n, q;
cin >> n >> q;
seg st;
st.init(n);
for (int i = 0; i < n; ++i) {
st.set(i, 0);
}
while (q--) {
int c;
cin >> c;
if (c == 2) {
int l, r, p;
cin >> l >> r >> p;
auto a = st.get(l - 1, r);
auto ans = upper_bound(a.begin(), a.end(), p) - a.begin();
cout << ans << endl;
} else {
int i, v;
cin >> i >> v;
--i;
st.set(i, v);
}
}
return 0;
}
/*
* @Nargulyev
*/
thanks!
Hello Codeforces!
Today I was solving one problem from codeforces edu
#include<bits/stdc++.h>
#define ll long long
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
struct segtree {
vector<int> tree;
int size;
const int zero = 0;
void init(int n) {
size = 1;
while (size < n)size *= 2;
tree.assign(size * 2 - 1, 0);
}
void build(vector<int> &a, int x, int lx, int rx) {
if (rx - lx == 1) {
if (lx < a.size())
tree[x] = a[lx];
} else {
int mid = (lx + rx) >> 1;
build(a, 2 * x + 1, lx, mid);
build(a, 2 * x + 2, mid, rx);
tree[x] = tree[2 * x + 1] + tree[2 * x + 2];
}
}
void build(vector<int> &a) {
init(a.size());
build(a, 0, 0, size);
}
void set(int i, int v, int x, int lx, int rx) {
if (rx - lx == 1) {
tree[x] = v;
return;
}
int mid = (lx + rx) >> 1;
if (i < mid)set(i, v, 2 * x + 1, lx, mid);
else set(i, v, 2 * x + 2, mid, rx);
tree[x] = tree[2 * x + 1] + tree[2 * x + 2];
}
void set(int i, int v) {
set(i, v, 0, 0, size);
}
int find(int k, int x, int lx, int rx) {
if (rx - lx == 1) {
return lx;
}
int m = (lx + rx) >> 1;
if (k < tree[2 * x + 1])return find(k, 2 * x + 1, lx, m);
else return find(k - tree[2 * x + 1], 2 * x + 2, m, rx);
}
int find(int k) {
find(k, 0, 0, size);
}
};
int32_t main() {
fast
int n, q;
cin >> n >> q;
vector<int> a(n);
for (auto &i: a)cin >> i;
segtree st;
st.build(a);
while (q--) {
int c;
cin >> c;
if (c == 1) {
int i;
cin >> i;
st.set(i, 1 - a[i]);
a[i] = 1 - a[i];
} else {
int k;
cin >> k;
cout << st.find(k) << endl;
}
}
return 0;
}
/*
* @Nargulyev
*/
Can someone tell me how I can solve this problem? (Sorry for my English)
Thanks!
+ It's my birthday today
Name |
---|