标签:
input | output |
---|---|
3 1 2 3 2 2 1 3 5 1 2 |
12 |
6 1 2 1 4 5 6 5 2 2 4 2 1 3 1 4 2 3 5 1 1 5 |
3 8 6 |
1 /** 2 Create By yzx - stupidboy 3 */ 4 #include <cstdio> 5 #include <cstring> 6 #include <cstdlib> 7 #include <cmath> 8 #include <deque> 9 #include <vector> 10 #include <queue> 11 #include <iostream> 12 #include <algorithm> 13 #include <map> 14 #include <set> 15 #include <ctime> 16 #include <iomanip> 17 using namespace std; 18 typedef long long LL; 19 typedef double DB; 20 #define MIT (2147483647) 21 #define INF (1000000001) 22 #define MLL (1000000000000000001LL) 23 #define sz(x) ((int) (x).size()) 24 #define clr(x, y) memset(x, y, sizeof(x)) 25 #define puf push_front 26 #define pub push_back 27 #define pof pop_front 28 #define pob pop_back 29 #define mk make_pair 30 31 inline int getInt() 32 { 33 int ret = 0; 34 char ch = ‘ ‘; 35 bool flag = 0; 36 while(!(ch >= ‘0‘ && ch <= ‘9‘)) 37 { 38 if(ch == ‘-‘) flag ^= 1; 39 ch = getchar(); 40 } 41 while(ch >= ‘0‘ && ch <= ‘9‘) 42 { 43 ret = ret * 10 + ch - ‘0‘; 44 ch = getchar(); 45 } 46 return flag ? -ret : ret; 47 } 48 49 const int N = 300010, M = 560; 50 int n, m; 51 LL block[N / M + 1][M], tag[N / M + 1], arr[N]; 52 53 inline int getBlockIndex(int x) 54 { 55 return x / M; 56 } 57 58 inline int getIndex(int x) 59 { 60 return x % M; 61 } 62 63 inline void input() 64 { 65 cin >> n; 66 for(int i = 0; i < n; i++) cin >> arr[i]; 67 } 68 69 inline LL work(int x) 70 { 71 int b = getBlockIndex(x), idx = getIndex(x); 72 return block[b][idx] + tag[b]; 73 } 74 75 inline LL query(int x) 76 { 77 x++; 78 LL ret = 0; 79 for(int i = 1; i * i <= x; i++) 80 if(x % i == 0) 81 { 82 ret += work(i - 1); 83 if(x / i != i) ret += work(x / i - 1); 84 } 85 return ret; 86 } 87 88 inline void change(int l, int r, int d) 89 { 90 int left = getBlockIndex(l), right = getBlockIndex(r); 91 for(int i = left + 1; i <= right - 1; i++) tag[i] += d; 92 if(left < right) 93 { 94 for(int i = getIndex(l); i < M; i++) block[left][i] += d; 95 for(int i = 0; i <= getIndex(r); i++) block[right][i] += d; 96 } 97 else 98 { 99 for(int i = getIndex(l); i <= getIndex(r); i++) 100 block[left][i] += d; 101 } 102 } 103 104 inline void solve() 105 { 106 for(cin >> m; m--; ) 107 { 108 int opt, l, r, x; 109 cin >> opt; 110 if(opt == 1) 111 { 112 cin >> x; 113 x--; 114 cout << query(x) + arr[x] << "\n"; 115 } 116 else 117 { 118 cin >> l >> r >> x; 119 l--, r--; 120 change(l, r, x); 121 } 122 } 123 } 124 125 int main() 126 { 127 ios::sync_with_stdio(0); 128 input(); 129 solve(); 130 return 0; 131 }
ural 2062 Ambitious Experiment
标签:
原文地址:http://www.cnblogs.com/StupidBoy/p/5241075.html