Test instructions
gives a sequence of n numbers. There's a m instruction below.
1 Instructions: The original sequence from L to R and
2 directives: sorted sequences from L to R and
Ideas
Line tree can do .... Sweeping through the record sum array can also
Code
#include <cstdio>#include <algorithm>#include <cstring>using namespace STD;#define LL Long LongConst intMAXN =100010;intNintS[MAXN];intSs[maxn];ll segtree[maxn<<2];ll ssegtree[maxn<<2];voidBuildintLintRintnode) {if(L = = r) {Segtree[node] = s[l];return; } Build (L, (l+r)/2,node<<1); Build ((L+R)/2+1, R, (node<<1)+1); Segtree[node] = segtree[node<<1]+segtree[(node<<1)+1];}voidBUILDD (intLintRintnode) {if(L = = r) {Ssegtree[node] = ss[l];return; } buildd (L, (l+r)/2,node<<1); BUILDD ((l+r)/2+1, R, (node<<1)+1); Ssegtree[node] = ssegtree[node<<1]+ssegtree[(node<<1)+1];} ll query (intAintBintLintRintnode) {if(R < A | | L > B)return 0;if(A <= l && R <= B)returnSegtree[node];returnQuery (a,b,l, (l+r)/2,node<<1) +query (A, B, (l+r)/2+1, R, (node<<1)+1);} ll Qquery (intAintBintLintRintnode) {if(R < A | | L > B)return 0;if(A <= l && R <= B)returnSsegtree[node];returnQquery (A,b,l, (l+r)/2,node<<1) +qquery (A, B, (l+r)/2+1, R, (node<<1)+1);}intMain () {scanf("%d", &n); for(inti =1; I <= N; i + +) {scanf("%d", &s[i]); Ss[i] = s[i]; } sort (ss+1, ss+n+1); Build1N1); BUILDD (1N1);intMscanf("%d", &m); while(m--) {intA,b,c;scanf("%d%d%d", &a,&b,&c);if(A = =1)printf("%i64d\n", Query (B,c,1N1));Else printf("%i64d\n", Qquery (B,c,1N1)); }return 0;}
Codeforces Round #248 (Div. 2) B-kuriyama Mirai ' s stones