题目链接:http://codeforces.com/contest/315/problem/B
开始以为线段树,汗……原来是道水题
1 #include <iostream> 2 #include <cstdio> 3 #include <cstdlib> 4 #include <cmath> 5 #include <cstring> 6 #include <vector> 7 #include <stack> 8 #include <map> 9 #include <queue> 10 using namespace std; 11 12 typedef struct Po { 13 int d, a; 14 }Po; 15 Po p[100000+10]; 16 int main(void) { 17 #ifndef ONLINE_JUDGE 18 freopen("187b.in", "r", stdin); 19 #endif 20 int n, m; 21 scanf("%d%d", &n, &m); 22 for (int i = 1; i <= n; ++i) { 23 scanf("%d", &p[i].a); 24 p[i].d = 0; 25 } 26 int D = 0, t, s; 27 for (int i = 0; i < m; ++i) { 28 scanf("%d", &t); 29 if (t == 1) { 30 int st, en; 31 scanf("%d%d", &st, &en); 32 p[st].a = en; 33 p[st].d = D; 34 } 35 else { 36 scanf("%d", &s); 37 if (t == 3) { 38 printf("%d\n", p[s].a + D - p[s].d); 39 } 40 else if (t == 2) { 41 D += s; 42 } 43 } 44 } 45 46 return 0; 47 }
也是纠结了好久才做出来的,果然是反应太慢了啊……比赛结果出来就过了这一道……又掉rating了。