int solve() { sort(sticks, sticks + N); int hi = sticks[N - 1]; int ans = 0; tree.init(sticks[N - 1]); for (int i = N - 4; i >= 2; --i) { int a = i + 1; for (int b = a + 1; b < N; ++b) for (int c = b + 1; c < N; ++c) { int v = max(1, sticks[c] - (sticks[a] + sticks[b])); tree.add(v, 1); } for (int j = i - 1; j >= 1; --j) for (int k = j - 1; k >= 0; --k) { int v = min(hi, sticks[i] + sticks[j] + sticks[k]); ans += tree.query(v - 1); } } return ans; }
int main(){ // freopen("input.txt", "r", stdin); Node lis[SZ]; int n; int test, val, pos, tc = 1; scanf("%d", &test); while( test-- ){ scanf("%d", &n); for(int i = 1; i <= n; i++){ scanf("%d", &val); lis[i] = Node(val, i); } sort(lis+1, lis+n+1); Bit bt = Bit(n); for(int idx = 1; idx <= n; idx++){ pos = lis[idx].pos; bt.add(pos, 1 + bt.query(pos-1)); } printf("Case %d: %lld\n", tc++, bt.query(n)); } return 0; }
int main() { int T; scanf("%d", &T); int ncase = 0; while (T--) { scanf("%d", &N); tree.init(N); for (int i = 1; i <= N; ++i) { int x; scanf("%d", &x); tree.add(i, x); } printf("Case %d:\n", ++ncase); scanf("%d", &M); while (M--) { int cmd; scanf("%d", &cmd); if (cmd == 1) { int x, y; scanf("%d%d", &x, &y); printf("%d\n", tree.query(x, y)); } else if (cmd == 2) { int x, y, p; scanf("%d%d%d", &x, &y, &p); tree.add(x, -p); tree.add(y, p); } } } return 0; }