Twelves Monkeys (multiset solution 141-zoj Monthly, July 2015-h)

Source: Internet
Author: User

Twelves Monkeys Time limit: 5 Seconds Memory Limit: 32768 KB

James Cole is a convicted criminal living beneath a post-apocalyptic Philadelphia. Many years ago, the Earth ' s surface had been contaminated by a virus so deadly that it forced the survivors to move Underg Round. In the years that followed, scientists had engineered a imprecise form of time travel. To earn a pardon, Cole allows scientists to send him on dangerous missions to the past to collect information on The virus, thought to has been released by a terrorist organization known as the Army of the twelve Monkeys.

The time travel was powerful so, sicentists can send Cole from year back to year x[i] y[i] . Eventually, Cole finds that Goines was the founder of the Army of the twelve Monkeys, and set out in search of him . When they find and confront him, however, Goines denies any involvement with the Viruscan. After that, Cole goes back and tells scientists what he knew. He wants to quit the mission to enjoy life. He wants to go, and the any of the year before, but scientists only allow him to use time travel once. In case of failure,Cole would find at least one route for backup. Him to calculate how many years he can go with at least, routes.

Input

The input file contains multiple test cases.

The first line contains three integers n , m , q (1≤ n ≤ 50000, 1≤ m ≤ 50000, 1≤ q ≤50000), indicating the M Aximum year, the number of time travel path and the number of queries.

The following m lines contains-integers x , y (1≤ y ≤ x ≤50000) indicating Cole can travel f Rom year to year x y .

The following q lines contains one integers p (1≤ p ≤n) indicating the year Cole was at now

Output

Should output one line, contain a number which are the total number of the yearCole can Go.

Sample Input
9 3 39 16 14 1672
Sample Output
501
Hint

6 can go back to 1 for the route. One is 6-1, and the other was 6-7-8-9-1.6 can go back to 2 for the route. One is 6-1-2, and the other is 6-7-8-9-1-2.


Test instructions: N time point, M time shuttle, tell the start and end of each shuttle, Q times, every time t time to ask how many points before the point can be reached by two different paths.

Train of thought: for the moment of inquiry T can shun time backwards to t+1,t+2,t+3 ... Then the T-moment and the subsequent time of the shuttle are possible, the time they can travel to insert multiset, if there is at least two elements in the Multiset value is greater than or equal to T, then the time t existence solution. It is also important to note that the moment of inquiry can be reached on the front, so we have to solve it from the back.

Code:

#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include < cmath> #include <string> #include <map> #include <stack> #include <vector> #include <set > #include <queue> #pragma comment (linker, "/stack:102400000,102400000") #define PI ACOs ( -1.0) #define EPS 1e-6# Define Lson rt<<1,l,mid#define Rson rt<<1|1,mid+1,r#define FRE (i,a,b) for (i = A; I <= b; i++) #define FREE ( I,A,B) for (i = A, I >= b; i--) #define FRL (i,a,b) for (i = A; I < b; i++) #define FRLL (i,a,b) for (i = A; i > b; i-- ) #define MEM (T, v) memset ((t), V, sizeof (t)) #define SF (n) scanf ("%d", &n) #define SFF (A, b) scanf ("%d%d",         &a, &b) #define SFFF (a,b,c) scanf ("%d%d%d", &a, &b, &c) #define PF Printf#define DBG  PF ("hi\n") typedef long long ll;using namespace std; #define INF 0x3f3f3f3f#define mod 1000000009const int maxn = 1005;const int MAXN = 1e5+10;struct edge{int u,v;} edge[maxn];struct node{int d,id;} Node[maxn];int CMP1 (Edge e1,edge E2) {return e1.u<e2.u;} int cmp2 (Node node1,node node2) {return node1.d<node2.d;}    multiset<int> s;int n,m,q;int ans[maxn],a[maxn];void Solve () {int i;    S.clear (); Sort (EDGE,EDGE+M,CMP1);    All two sorted by date from small to large sort (NODE,NODE+Q,CMP2);    int pos=m-1;        for (i=q-1;i>=0;i--)//From the back of the sweep, because the front of the moment can be the time to reach the back of the {int day=node[i].d;        int cnt=0;            while (Pos>=0&&edge[pos].u>=day) {S.insert (EDGE[POS].V);        pos--;            } for (Multiset<int>::iterator it=s.begin (); It!=s.end (); it++) {a[cnt++]=* (IT);        if (cnt>=2) break;        } if (Cnt>=2&&a[1]<=day) ans[node[i].id]=day-a[1];    else ans[node[i].id]=0;    } for (i=0;i<q;i++) pf ("%d\n", Ans[i]); return;} int main () {#ifndef Online_judge freopen ("C:/users/lyf/desktop/in.txt", "R", stdin); #endif iNT I,j,t;        while (~SFFF (n,m,q)) {for (i=0;i<m;i++) SFF (EDGE[I].U,EDGE[I].V);            for (i=0;i<q;i++) {SF (NODE[I].D);        Node[i].id=i;    } solve (); } return 0;}



Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Twelves Monkeys (multiset solution 141-zoj Monthly, July 2015-h)

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.