51nod 1107 (tree-like array, reverse order number)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.