fork download
  1. // ROOT : DRAGON3012009
  2. #include <bits/stdc++.h>
  3. #define ll long long
  4. #define ld long double
  5. #define el "\n"
  6. #define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  7. #define __ROOT__ int main()
  8. #pragma GCC optimize("O2")
  9. #define FOR(i,l,r) for(int i = l ; i <= r ; i ++)
  10. #define FORD(i,r,l) for(int i = r ; i >= l ; i --)
  11. #define REP(i, a ) for(int i = 0 ; i < a ; i ++ )
  12. #define fi first
  13. #define se second
  14. #define M 1000000007
  15. #define MAXN 100001
  16. #define INF (1ll<<30)
  17. #define BLOCK_SIZE 800
  18. #define MAX_NODE 1001001
  19. #define LOG 19
  20. #define ALPHA_SIZE 26
  21. #define BASE 311
  22. #define NAME "file"
  23. #define compare(v) sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end());
  24. using namespace std;
  25. const ll MOD[] = {(ll)1e9 + 2277, (ll)1e9 + 5277, (ll)1e9 + 8277, (ll)1e9 + 9277, (ll) 1e9 + 7 };
  26. const ll NMOD = 1;
  27. const int dx[] = {-1, 0, 1,0};
  28. const int dy[] = {0, 1, 0, -1};
  29. //**Variable**//
  30. ll n, m, cnt_heavy = 0, q ;
  31. ll arr[MAXN];
  32. ll lazy[MAXN] ;
  33. ll sum[MAXN] ;
  34. ll real_pos[MAXN] ;
  35. ll cnt[MAXN/BLOCK_SIZE+100][MAXN] ; // giao nặng nhẹ
  36. //**Struct**//
  37. struct S {
  38. vector<ll> Set;
  39. ll sz, id ;
  40. bool operator < ( const S &other ) const {
  41. return sz > other.sz ;
  42. }
  43. };
  44. S s[ 2 * MAXN ];
  45. //**Function**//
  46. template<class X, class Y >
  47. bool minimize(X & x, const Y &y ) {
  48. return x > y ? x = y, 1:0 ;
  49. }
  50. template<class X, class Y >
  51. bool maximize(X &x, const Y &y ) {
  52. return x < y ? x = y, 1:0 ;
  53. }
  54. bool exitt[MAXN] ;
  55. void init() {
  56. cin>>n >> m >> q ;
  57. FOR(i,1, n) cin >> arr[i] ;
  58. FOR(i, 1, m) {
  59. cin>>s[i].sz ;
  60. s[i].Set.resize(s[i].sz) ;
  61. FOR(j, 0, s[i].sz -1 ) cin>> s[i].Set[j] ;
  62. s[i].id = i ;
  63. if(s[i].sz >= BLOCK_SIZE) cnt_heavy ++ ;
  64. }
  65. sort(s + 1, s + m + 1) ;
  66. FOR(i, 1, m ) {
  67. real_pos[s[i].id] = i ;
  68. }
  69.  
  70. FOR(i, 1, cnt_heavy) {
  71. for(ll v : s[i].Set) {
  72. exitt[v] = true ;
  73. }
  74. FOR(j, 1, m ) {
  75. for(ll val : s[j].Set) {
  76. cnt[i][j] += exitt[val] ;
  77. }
  78. }
  79. for(ll v : s[i].Set) {
  80. exitt[v] = false ;
  81. }
  82. }
  83. FOR(i, 1, m ) {
  84. for(ll p : s[i].Set) sum[i] += arr[p] ;
  85. }
  86. memset(arr, 0, sizeof arr) ;
  87. }
  88. void solve() {
  89. FOR(i, 1, q) {
  90. ll p, value;
  91. char t;
  92. cin >> t;
  93. if (t == '+') {
  94. cin >> p >> value;
  95. p = real_pos[p];
  96. if (s[p].sz >= BLOCK_SIZE) {
  97. lazy[p] += value;
  98. } else {
  99. FOR(j, 1, cnt_heavy) sum[j] += value * cnt[j][p];
  100. for (ll pos : s[p].Set) arr[pos] += value;
  101. }
  102. } else {
  103. cin >> p;
  104. p = real_pos[p];
  105. if (s[p].sz >= BLOCK_SIZE) {
  106. ll ans = sum[p];
  107. FOR(j, 1, cnt_heavy)
  108. ans += lazy[j] * cnt[j][p];
  109. cout << ans << el;
  110. } else {
  111. ll ans = sum[p] ;
  112. for (ll pos : s[p].Set) ans += arr[pos];
  113. FOR(j, 1, cnt_heavy) ans += lazy[j] * cnt[j][p];
  114. cout << ans << el;
  115. }
  116. }
  117. }
  118. }
  119.  
  120.  
  121. __ROOT__ {
  122. // freopen(NAME".inp" , "r" , stdin);
  123. // freopen(NAME".out" , "w", stdout) ;
  124. fast;
  125. int t =1 ;// cin >> t;
  126. while(t-- ) {
  127. init();
  128. solve();
  129. }
  130. }
  131.  
Success #stdin #stdout 0.01s 14944KB
stdin
5 3 5
5 -5 5 1 -4
2 1 2
4 2 1 4 5
2 2 5
? 2
+ 3 4
? 1
+ 2 1
? 2
stdout
-3
4
9