aboutsummaryrefslogtreecommitdiff
path: root/semestr-4/aisd/pracownia4/brut.cpp
blob: 32f4ebbecb2bdce80e63e24c3e4dddcd63b64e4e (plain)
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
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

struct insert_list {
    vector<int> v;
    
    insert_list() {
    }

    void insert(int p, int val) {
        assert(p <= v.size());
        assert(p >= 0);
        vector<int> temp;
        for (int i = 0; i < p; i++) {
            temp.push_back(v[i]);
        }
        temp.push_back(val);
        for (int i = p; i < v.size(); i++) {
            temp.push_back(v[i]);
        }
        v = temp;
    }

    void erase(int p) {
        assert(p <= v.size());
        assert(p >= 1);
        vector<int> temp;
        for (int i = 0; i < p-1; i++) {
            temp.push_back(v[i]);
        }
        for (int i = p; i < v.size(); i++) {
            temp.push_back(v[i]);
        }
        v = temp;
    }

    ll sum(int l, int r) {
        ll ans = 0;
        for (int i = l-1; i < r; i++) {
            ans += v[i];
        }
        return ans;
    }
};  

insert_list v;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie();
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        char c;
        cin >> c;
        if (c == 'D') {
            int a;
            cin >> a;
            v.erase(a);
        }
        else {
            int a, b;
            cin >> a >> b;
            if (c == 'I') v.insert(a, b);
            else cout << v.sum(a,b) << "\n";
        }
    }
}