Title Link: https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1107
Idea: In fact, is the upgrade version of the reverse number, X coordinate as a position, y coordinate as a value Val, but there may be equal number, a little modification can be.
#include <bits/stdc++.h>using namespace Std;typedef long long ll;const int N = 5e4 + 3;int lowbit (int x) {return x & (-X);} struct node{int x,y,order;} Q[n];int A[n],c[n],n;bool cmp1 (node T1,node T2) {if (t1.x! = t2.x) return t1.x < t2.x; return t1.y < t2.y;} BOOL CMP2 (node T1,node T2) {if (t1.y! = t2.y) return t1.y < t2.y; return T1.order < T2.order;} void Update (int pos,int val) {for (int i = pos; I <= n; i + = Lowbit (i)) c[i] + = val;} int sum (int pos) {int ans = 0; for (int i = pos; i > 0; I-= Lowbit (i)) ans + = c[i]; return ans;} int main () {scanf ("%d", &n); for (int i = 1; I <= n; i++) scanf ("%d%d", &q[i].x,&q[i].y); Sort (Q+1,Q+N+1,CMP1); for (int i = 1; I <= n; i++) q[i].order = i; Sort (Q+1,Q+N+1,CMP2); for (int i = 1; I <= n; i++) A[q[i].order] = i; int ans = 0; for (int i = 1; I <= n; i++) {update (a[i],1); Ans + = I-sum (a[I]); } printf ("%d\n", ans); return 0;}
51nod 1107 (tree-like array, reverse order number)