POJ3067 Japan
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 26270 | Accepted: 7132 |
Description
Input
Output
Test case (case number): (number of crossings)
Sample Input
1
3 4 4
1 4
2 3
3 2
3 1
Sample Output
Test case 1: 5
Source
/**/
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
const int mxn=;
struct edge{
int x,y;
}e[mxn*];
int cmp(edge a,edge b){
if(a.x!=b.x)return a.x<b.x;
return a.y<=b.y;
}
long long t[mxn];
int n,m,k;
int a[mxn];
inline int lowbit(int x){
return x&-x;
}
void add(int p,int v){
while(p<=m){
t[p]+=v;
p+=lowbit(p);
}
return;
}
int sum(int p){
int res=;
while(p){
res+=t[p];
p-=lowbit(p);
}
return res;
}
int main(){
int T;
scanf("%d",&T);
int i,j;
int cas=;
while(T--){
long long ans=;
memset(t,,sizeof t);
scanf("%d%d%d",&n,&m,&k);
for(i=;i<=k;i++) scanf("%d%d",&e[i].x,&e[i].y);
sort(e+,e+k+,cmp);
for(i=;i<=k;i++){
ans+=sum(m)-sum(e[i].y);
add(e[i].y,);
}
printf("Test case %d: %lld\n",++cas,ans);
}
return ;
}
POJ3067 Japan的更多相关文章
- poj3067 Japan(树状数组)
转载请注明出处:http://blog.csdn.net/u012860063 题目链接:id=3067">http://poj.org/problem? id=3067 Descri ...
- poj3067 Japan 树状数组求逆序对
题目链接:http://poj.org/problem?id=3067 题目就是让我们求连线后交点的个数 很容易想到将左端点从小到大排序,如果左端点相同则右端点从小到大排序 那么答案即为逆序对的个数 ...
- POJ3067:Japan(线段树)
Description Japan plans to welcome the ACM ICPC World Finals and a lot of roads must be built for th ...
- POJ 3067 Japan(树状数组)
Japan Time Limit: 10 ...
- Japan
Japan plans to welcome the ACM ICPC World Finals and a lot of roads must be built for the venue. Jap ...
- POJ 3067 Japan
Japan Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 25489 Accepted: 6907 Descriptio ...
- cdoj 383 japan 树状数组
Japan Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/problem/show/383 Descrip ...
- Day 3 @ RSA Conference Asia Pacific & Japan 2016 (morning)
09.00 – 09.45 hrs Tracks Cloud, Mobile, & IoT Security A New Security Paradigm for IoT (Inter ...
- Day 4 @ RSA Conference Asia Pacific & Japan 2016
09.00 – 09.45 hrs Advanced Malware and the Cloud: The New Concept of 'Attack Fan-out' Krishna Naraya ...
随机推荐
- Web前端 优化方案
1.减少Http请求 在一个页面中图片,CSS,JS可能N个,如果每个资源都去请求一次服务器的话,那么服务器就会为每个资源开一个线程来完成,这样的话对服务器的压力就很大了.所以解决的方法就是合并资源 ...
- Bootstrap历练实例:带列表组的面板
带列表组的面板 我们可以在任何面板中包含列表组,通过在 <div> 元素中添加 .panel 和 .panel-default 类来创建面板,并在面板中添加列表组.您可以从 列表组 一章中 ...
- C#传递数组参数
在C#中,可以将数组作为参数传递给方法,同时方法可以更改数组元素的值. 一.将一维数组作为参数传递给方法 using System;using System.Collections.Generic;u ...
- Java基础面试操作题:Java代理工厂设计模式 ProxyFactory 有一个Baby类,有Cry行为,Baby可以配一个保姆 但是作为保姆必须遵守保姆协议:能够处理Baby类Cry的行为,如喂奶、哄睡觉。
package com.swift; public class Baby_Baomu_ProxyFactory_Test { public static void main(String[] args ...
- ios 设计模式总结
设计模式:备注:消息传递模型(Message Passing)是Objective-C语言的核心机制.在Objective-C中,没有方法调用这种说法,只有消息传递.在C++或Java中调用某个类的方 ...
- 【细节题 离线 树状数组】luoguP4919 Marisa采蘑菇
歧义差评:但是和题意理解一样了之后细节依然处理了很久,说明还是水平不够…… 题目描述 Marisa来到了森林之中,看到了一排nn个五颜六色的蘑菇,编号从1-n1−n,这些蘑菇的颜色分别为col[1], ...
- shell 练习 - 第七周
1. 用shell实现传入进程pid, 查看对应进程/proc下CPU.内存指标 #!/bin/bash read -p "Input PID Value: " pid pid_e ...
- 设置mysql允许外部连接访问
错误信息: SQL Error (1130): Host ‘192.168.1.88’ is not allowed to connect to this MySQL server 说明所连接的用户帐 ...
- OpenCV编译 Make出错 recipe for target 'modules/imgproc/CMakeFiles/opencv_test_imgproc.dir/all' failed
OpenCV编译 Make出错 recipe for target 'modules/imgproc/CMakeFiles/opencv_test_imgproc.dir/all' failed 添 ...
- GoF23种设计模式之行为型模式之备忘录模式
一.概述 在不破坏封装性的前提下,捕获一个对象的内部状态,并在该对象的外部保存这个状态.以便以后可以将该对象恢复到原先保存的状态. 二.适用性 1.当需要保存一个对象在某个时刻的状态( ...