LOJ #6278. Getting started with series partitioning 2,

Source: Internet
Author: User

LOJ #6278. Getting started with series partitioning 2,
Memory limit: 256 MiB time limit: 500 ms standard input/output question type: traditional evaluation method: text comparison uploaded by: hzwer submit Record Statistics Discussion test data question description

A series with a length of nnn and nnn operations are provided. the operation involves addition of intervals and queries the number of elements smaller than a certain value of xxx.

Input Format

Enter a number nnn in the first line.

Enter nnn numbers in the second row. the I-th digit is aia_iai, separated by spaces.

Next, enter the nnn line and enter four numbers in each line: opt \ mathrm {opt} opt, lll, rrr, and ccc, separated by spaces.

If opt = 0 \ mathrm {opt} = 0opt = 0, the numbers between [l, r] [l, r] [l, r] are added with ccc.

If opt = 1 \ mathrm {opt} = 1opt = 1, it indicates querying [l, r] [l, r] [l, r, number of digits smaller than C2C ^ 2c2.

Output Format

For each query, a row of numbers is output to indicate the answer.

Sample Input
41 2 2 30 1 3 11 1 3 21 1 4 11 2 3 2
Sample output
302
Data range and prompt

For data of 100% 100 \ % 100%, 1 ≤ n ≤ 50000, − 231 ≤ others 1 \ leq n \ leq 50000, -2 ^ {31} \ leq \ mathrm {others} 1 ≤ n ≤ 50000, − 231 ≤ others, ans ≤ 231 − 1 \ mathrm {ans} \ leq 2 ^ {31}-1ans ≤ 231 − 1.

 

We can follow the normal train of thought for the interval and.

For the second query, we can use vector to maintain the ordered table in each block,

Fragmented blocks are directly violent; otherwise, binary blocks are in the vector.

Note that the number of the vector starts from 0.

 

 

# Include <cstdio> # include <cstring> # include <algorithm> # include <cmath> # include <vector> using namespace std; const int MAXN = 1e6 + 10; const int INF = 1e8 + 10; inline char nc () {static char buf [MAXN], * p1 = buf, * p2 = buf; return p1 = p2 & (p2 = (p1 = buf) + fread (buf, 1, MAXN, stdin), p1 = p2 )? EOF: * p1 ++;} inline int read () {char c = nc (); int x = 0, f = 1; while (c <'0' | c> '9') {if (c = '-') f =-1; c = nc ();} while (c> = '0' & c <= '9') {x = x * 10 + c-'0'; c = nc ();} return x * f;} vector <int> v [1001]; // use a vector to store the int block, L [MAXN], R [MAXN], a [MAXN], tag [MAXN], belong [MAXN], N; void Sort (int p) {v [p]. clear (); for (int I = L [p * block]; I <= min (R [p * block], N); I ++) v [p]. push_back (a [I]); sort (v [p]. begin (), v [p]. end ();} void IntervalAdd (Int l, int r, int val) {for (int I = l; I <= min (r, R [l]); I ++) a [I] + = val; Sort (belong [l]); if (belong [l]! = Belong [r]) {for (int I = L [r]; I <= r; I ++) a [I] + = val; sort (belong [r]);} for (int I = belong [l] + 1; I <= belong [r]-1; I ++) tag [I] + = val;} int Query (int l, int r, int val) {int ans = 0; for (int I = l; I <= min (r, R [l]); I ++) if (a [I] + tag [belong [l] <val) ans ++; if (belong [l]! = Belong [r]) for (int I = L [r]; I <= r; I ++) if (a [I] + tag [belong [r] <val) ans ++; for (int I = belong [l] + 1; I <= belong [r]-1; I ++) {int x = val-tag [I]; ans + = lower_bound (v [I]. begin (), v [I]. end (), x)-v [I]. begin ();} return ans;} int main () {# ifdef WIN32 freopen (". in "," r ", stdin); freopen (" B. out "," w ", stdout); # else # endif N = read (); block = sqrt (N); for (int I = 1; I <= N; I ++) a [I] = read (); for (int I = 1; I <= N; I ++) belong [I] = (I-1) /block + 1, L [I] = (belong [I]-1) * block + 1, R [I] = belong [I] * block; for (int I = 1; I <= N; I ++) v [belong [I]. push_back (a [I]); for (int I = 1; I <= belong [N]; I ++) Sort (I); for (int I = 1; I <= N; I ++) {int opt = read (), l = read (), r = read (), c = read (); if (opt = 0) IntervalAdd (l, r, c); else printf ("% d \ n", Query (l, r, c * c ));} return 0 ;}

 

 

 

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.