Poj3067 Japan tree array & Reverse Order

Source: Internet
Author: User

When you understand the question, you will find that this is a question of reverse order. Use a as the first keyword, and B as the second keyword to sort the original input data in ascending order. Then, for each B, check whether there are several bigger ones.

 

# Include <iostream> # include <algorithm> # include <cstdio> # include <cstring> using namespace STD; struct way {int A, B; bool operator <(const struct way t) const {return a <t. A | A = T. A & B <t. B ;}} P [1000005]; int C [1005], t, n, m, K; inline int lowbit (int K) {return K & (-k );} void insert (int I, int d) {While (I <= m) {C [I] + = D; I + = lowbit (I );}} int getsum (int I) {int T = 0; while (I) {T + = C [I]; I-= lowbit (I) ;}return t ;} int main () {scanf ("% d", & T); int c = 1; _ int64 sum; while (t --) {scanf ("% d", & N, & M, & K); For (INT I = 0; I <K; I ++) scanf ("% d", & P [I]. a, & P [I]. b); sort (p, p + k); sum = 0; memset (C, 0, sizeof (INT) * (m + 1 )); for (INT I = 0; I <K; I ++) {sum + = getsum (M)-getsum (P [I]. b); insert (P [I]. b, 1) ;}printf ("Test Case % d: % i64d \ n", C ++, sum) ;}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.