POJ 3067 Japan (tree-like array) __ data structure: tree-like array

Source: Internet
Author: User
Tree-like array routines so, to determine an axis, but just learn to build a bad build.
Main.cpp//Richard////Created by Shaojinjie on 16/8/21. COPYRIGHT©2016 year Shaojinjie.
All rights reserved. #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace
Std
typedef long Long LL;
const int MAXN=1000+10;
LL C[MAXN];
    struct edge{int u,v;
        BOOL operator < (const edge &e) Const {if (U!=E.U) return u<e.u;
    Return v<e.v;
}}edge[500000];
int n,m,k;
        void Add (int x) {while (x<=m) {c[x]++;
    x+= (x& (-X));
    } ll sum (int x) {ll s=0;
        while (x) {s+=c[x];
    x-= (x& (-X));
return s;
    int main () {int t,kase=0;
    scanf ("%d", &t);
        while (t--) {memset (c,0,sizeof (c));
        scanf ("%d%d%d", &n,&m,&k);
        for (int i=0;i<k;i++) {scanf ("%d%d", &AMP;EDGE[I].U,&AMP;EDGE[I].V);
        Sort (edge,edge+k);
        LL ans=0; for (int i=0;i<k;i++) {ans+=sum (M)-sum (EDGE[I].V);
        Add (EDGE[I].V);
    printf ("Test Case%d:%lld\n", ++kase,ans);
return 0; }

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.