"BZOJ4378" [Poi2015]logistyka "tree-like array" "concluding question"

Source: Internet
Author: User

"Topic link"

Exercises

First, there is a conclusion: the number of numbers greater than S is K (if K is greater than C, obviously Tak.) Here we discuss K <= c), then there must be a solution if the number is less than s and not less than (c-k) * S.

Will not prove that ...

Use a tree-like array to record the number of numbers and numbers, and then judge it.


Complexity of:

Complexity of Time: O (MLOGM), spatial complexity: O (M).


1 A.


GET:

Conclusion question ...

/* telekinetic Forest Guard */#include <cstdio> #include <cstring> #include <algorithm>using namespace Std;typedef Long Long ll;const int maxn = 1000005;int N, m, NUM[MAXN], DISC[MAXN], tot, TRNUM[MAXN]; LL trsum[maxn];struct _que {int opt, a, b;} que[maxn];inline int iread () {int f = 1, x = 0; char ch = getchar (); for (; Ch & Lt ' 0 ' | | Ch > ' 9 '; ch = getchar ()) F = ch = = '-'? -1:1;for (; Ch >= ' 0 ' && ch <= ' 9 '; ch = getchar ()) x = x * + ch-' 0 '; return f * x;} inline int find (int x) {int L = 1, R = Tot;while (L <= r) {int mid = L + R >> 1;if (Disc[mid] < x) L = mid + 1;e LSE if (Disc[mid] = = x) return mid;else r = mid-1;}} inline void Addnum (int x, int c) {for (; x <= tot; x + = x & x) trnum[x] + = C;} inline int querynum (int x) {int res = 0;for (; x; x = x & x) Res + = Trnum[x];return res;} inline void addsum (int x, int c) {for (; x <= tot; x + = x & x) trsum[x] + = C;} inline LL querysum (int x) {LL res = 0;for (; x; x-= x &-X) Res + = Trsum[x];return res;} int main () {iread (); m = Iread (); for (int i = 1, i <= m; i++) {Char ch = getchar (); for (; ch! = ' U ' && ch! = ' Z ') ; ch = getchar ()); que[i].a = Iread (); que[i].b = Disc[++tot] = Iread (); que[i].opt = (ch = = ' U ');} Sort (disc + 1, disc + 1 + tot), tot = unique (disc + 1, disc + 1 + tot)-(disc + 1); for (int i = 1; I <= m; i++) if (Que[i] . opt = = 1) {int x = que[i].a, y = Find (que[i].b), if (!num[x] && que[i].b) addnum (y, 1), N++;else if (Num[x] &&am p;!que[i].b) Addnum (y,-1), N--;else if (num[x] && que[i].b) addnum (Find (Num[x]),-1), Addnum (y, 1); if (Num[x]) add Sum (Find (num[x]),-num[x]), if (que[i].b) addsum (y, que[i].b); num[x] = que[i].b;} else {int x = que[i].a, y = Find (que[i].b), int k = N-querynum (y), if (k > x) printf ("tak\n"); else {LL sum = querysum (y) ;p rintf (sum >= (LL) (x-k) * que[i].b? "tak\n": "nie\n");}} return 0;}


"BZOJ4378" [Poi2015]logistyka "tree-like array" "concluding question"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.