treap分離合併区間動作poj 3468
5104 ワード
A Simple Proble with Integers
Time Limit:5000 MS
メモリLimit:13131313722 K
Total Submissions:53831
Acctepted:16158
Case Time Limit:2000 MS
Description
You have N integers,A 1,A 2,…,AN.You need to deal with two kinds of operation.One type of operation is to add some given to each number.The other is to ask for the sum of nbers.inven.inven.given.
Input
The first line contains two numbers N and Q.1≦N、Q≦100000.The second line contains N numbers、the initial values of A 1,A 2,...AN.-100000≦Ai≦100000 000 000.Each of the nexxt line Q inininesents s rerereesents+1.aapaneneinininininininininininininininininininininininininininininininininininininininininininininininininents+1.aatos+1.atos+1.aaaaatos+1.aaaasum of Aa,A+1,…,Ab.
Output
You need to answer all Q command in order.One answer in a line.
Sample Input
The sums may exceed the range of 32-bit integers.
題意は簡単で、区間の増減、区間の和を求めます.
fhq treapを勉強して、各区間の操作で区間をカットして、操作が終わったらmergeで帰ります.不思議です.debugは二日間で、やっとacしました.
コード:
Time Limit:5000 MS
メモリLimit:13131313722 K
Total Submissions:53831
Acctepted:16158
Case Time Limit:2000 MS
Description
You have N integers,A 1,A 2,…,AN.You need to deal with two kinds of operation.One type of operation is to add some given to each number.The other is to ask for the sum of nbers.inven.inven.given.
Input
The first line contains two numbers N and Q.1≦N、Q≦100000.The second line contains N numbers、the initial values of A 1,A 2,...AN.-100000≦Ai≦100000 000 000.Each of the nexxt line Q inininesents s rerereesents+1.aapaneneinininininininininininininininininininininininininininininininininininininininininininininininininents+1.aatos+1.atos+1.aaaaatos+1.aaaasum of Aa,A+1,…,Ab.
Output
You need to answer all Q command in order.One answer in a line.
Sample Input
10 5
1 2 3 4 5 6 7 8 9 10
Q 4 4
Q 1 10
Q 2 4
C 3 6 3
Q 2 4
Sample Output4
55
9
15
ベントThe sums may exceed the range of 32-bit integers.
題意は簡単で、区間の増減、区間の和を求めます.
fhq treapを勉強して、各区間の操作で区間をカットして、操作が終わったらmergeで帰ります.不思議です.debugは二日間で、やっとacしました.
コード:
/* ***********************************************
Author :xianxingwuguan
Created Time :2014/3/5 22:03:29
File Name :1.cpp
************************************************ */
#pragma comment(linker, "/STACK:102400000,102400000")
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include