// yukicoder: No.789 範囲の合計 // 2019.5.4 bal4u #include #include #if 1 #define gc() getchar_unlocked() #define pc(c) putchar_unlocked(c) #else #define gc() getchar() #define pc(c) putchar(c) #endif int in() { // 非負整数の入力 int n = 0, c = gc(); do n = 10 * n + (c & 0xf), c = gc(); while (c >= '0'); return n; } // Bit木 library #define MAX 100010 int bit[MAX << 1]; int bn; int sum(int i) { int s = 0; while (i > 0) s += bit[i], i -= i & -i; return s; } void add(int i, int x) { while (i <= bn) bit[i] += x, i += i & -i; } int cmd[MAX][3], n; int x[MAX << 1], sz; int cmp(const void *a, const void *b) { return *(int *)a - *(int *)b; } int uniq(int *a, int n) { int i, j; for (i = 0, j = 1; j < n; j++) { while (j < n && a[j] == a[i]) j++; if (j < n) if (++i != j) a[i] = a[j]; } return i+1; } int bsch(int v, int r) { int m, l = 0; while (l < r) { m = (l+r)/2; if (x[m] == v) break; if (x[m] < v) l = m+1; else r = m; } return m; } int main() { int i, k, a, b; long long ans; n = in(), sz = 0; for (i = 0; i < n; i++) { cmd[i][0] = k = gc() & 1, gc(); cmd[i][1] = a = in(), cmd[i][2] = b = in(); if (k) x[sz++] = a, x[sz++] = b; else x[sz++] = a; } qsort(x, sz, sizeof(int), cmp); sz = uniq(x, sz); ans = 0, bn = sz+1; for (i = 0; i < n; i++) { if (cmd[i][0]) { b = bsch(cmd[i][2], sz); a = bsch(cmd[i][1], b+1); ans += sum(b+1); if (a > 0) ans -= sum(a); } else { a = bsch(cmd[i][1], sz); add(a+1, cmd[i][2]); } } printf("%lld\n", ans); return 0; }