Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- ======================
- [ ___T_ ]
- [ | 6=6 | =>HI :-)]
- [ |__o__| ]
- [ >===]__o[===< ]
- [ [o__] ]
- [ .". ]
- [ |_| ]
- [ ]
- ======================
- */
- #include <bits/stdc++.h>
- using namespace std;
- struct item {
- int m,c;
- };
- struct Tree {
- int size = 1;
- vector<item> values;
- void init (int n) {
- while (size < n) size *= 2;
- values.resize(2 * size);
- }
- item merge (item a,item b) {
- if (a.m < b.m) return a;
- if (a.m > b.m) return b;
- return {a.m,a.c + b.c};
- }
- item single (int v) {
- return {v,1};
- }
- item NEUTRAL_ELEMENT = {INT_MAX,0};
- void build (vector<int> &a,int x,int lx,int rx) {
- if (rx - lx == 1) {
- if (lx < (int) a.size()) {
- values[x] = single (a[lx]);
- }
- return;
- }
- int m = (lx + rx) / 2;
- build (a,2 * x + 1,lx,m);
- build (a,2 * x + 2,m,rx);
- values[x] = merge (values[2 * x + 1],values[2 * x + 2]);
- }
- void build (vector<int> &a) {
- build (a,0,0,size);
- }
- void set (int i,int v,int x,int lx,int rx) {
- if (rx - lx == 1) {
- values[x] = single(v);
- return;
- }
- int m = (lx + rx) / 2;
- if (i < m) {
- set (i,v,2 * x + 1,lx,m);
- } else {
- set (i,v,2 * x + 2,m,rx);
- }
- values[x] = merge (values[2 * x + 1],values[2 * x + 2]);
- }
- void set (int i,int v) {
- set (i,v,0,0,size);
- }
- item calc (int l,int r,int x,int lx,int rx) {
- if (lx >= r or l >= rx) return NEUTRAL_ELEMENT;
- if (lx >= l and rx <= r) return values[x];
- int m = (lx + rx) / 2;
- return merge(calc(l,r,2 * x + 1,lx,m),calc (l,r,2 * x + 2,m,rx));
- }
- item calc (int l,int r) {
- return calc(l,r,0,0,size);
- }
- };
- int main () {
- ios::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- int T = 1;
- //~ cin >> T;
- for (int test_case = 1; test_case <= T; ++test_case) {
- int n,m;
- cin >> n >> m;
- Tree st;
- st.init(n);
- vector<int> a(n);
- for (int i = 0; i < n; ++i) {
- cin >> a[i];
- }
- st.build (a);
- for (int i = 1; i <= m; ++i) {
- int type;
- cin >> type;
- if (type == 1) {
- int idx,v;
- cin >> idx >> v;
- st.set(idx,v);
- } else {
- int l,r;
- cin >> l >> r;
- item res = st.calc(l,r);
- cout << res.m << " " << res.c << "\n";
- }
- }
- }
- //cerr << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement