Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- using ll = long long;
- ll sum = 0;
- struct Node {
- Node *left, *right;
- ll val;
- int prior, sz;
- Node(ll new_val = 0LL) {
- left = right = nullptr;
- val = new_val;
- prior = rand();
- sz = 1;
- }
- };
- int safe_get_size(Node *root) {
- if (!root)
- return 0;
- return root->sz;
- }
- void relax(Node *root) {
- if (!root)
- return;
- root->sz = safe_get_size(root->left) + safe_get_size(root->right) + 1;
- }
- Node *merge(Node *L, Node *R) {
- if (!L)
- return R;
- if (!R)
- return L;
- if (L->prior < R->prior) {
- L->right = merge(L->right, R);
- relax(L);
- return L;
- } else {
- R->left = merge(L, R->left);
- relax(R);
- return R;
- }
- }
- pair<Node*, Node*> split(Node *root, int k) {
- if (!root)
- return {nullptr, nullptr};
- if (safe_get_size(root->left) >= k) {
- auto p = split(root->left, k);
- root->left = p.second;
- relax(root);
- return {p.first, root};
- } else {
- auto p = split(root->right, k - safe_get_size(root->left) - 1);
- root->right = p.first;
- relax(root);
- return {root, p.second};
- }
- }
- void outt(Node *root) {
- if (root->left) {
- outt(root->left);
- }
- cout << root->val << " " << safe_get_size(root) << "\n";
- if (root->right) {
- outt(root->right);
- }
- }
- int main() {
- freopen("input.txt", "r", stdin), freopen("a.out", "w", stdout);
- // freopen("hall.in", "r", stdin), freopen("hall.out", "w", stdout);
- ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
- int n, type;
- cin >> n >> type;
- Node *root = nullptr;
- for (int i = 0; i < n; ++i) {
- ll cur_len;
- cin >> cur_len;
- sum += cur_len * cur_len;
- Node *v = new Node(cur_len);
- root = merge(root, v);
- }
- cout << sum << "\n";
- int q;
- cin >> q;
- while (q--) {
- int e, v;
- cin >> e >> v;
- if (e == 1) {
- } else {
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment