zoj 月赛

141 - ZOJ Monthly, July 2015 - H
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 underground. In the years that followed, scientists had engineered an 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 have been released by a terrorist organization known as the Army of the Twelve Monkeys.

The time travel is powerful so that sicentists can send Cole from year x[i] back to year y[i]. Eventually, Cole finds that Goines is 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 back to the any year before current year, but scientists only allow him to use time travel once. In case of failure, Cole will find at least one route for backup. Please help him to calculate how many years he can go with at least two 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 maximum year, the number of time travel path and the number of queries.

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

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

Output

For each test case, you should output one line, contain a number which is the total number of the year Cole can go.

Sample Input
9 3 3
9 1
6 1
4 1
6
7
2
Sample Output
5
0
1
Hint

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




#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <queue>
#include <set>
#include <iostream>

using namespace std;
#define maxn 50000 + 10
#define INF 0x7ffffff

int n, m, q;
int a[maxn];

struct col
{
    int from, to;
}c[maxn];

int cmp(col a, col b)
{
    return a.from < b.from;
}

int year[maxn];

int main()
{
    while(~scanf("%d%d%d", &n, &m, &q))
    {

        for(int i=0; i<m; i++)
            scanf("%d%d", &c[i].from, &c[i].to);

        sort(c, c+m, cmp);
        multiset<int> S;
        S.insert(c[m-1].to);

        a[m-1] = a[m] = INF;
        for(int i=m-2; i>=0; i--)
        {
            S.insert(c[i].to);
            a[i] = *(++S.begin());
        }

        for(int i=0; i<m; i++)
            year[i] = c[i].from;

        int t, pos;
        for(int i=0; i<q; i++)
        {
            scanf("%d", &t);
            pos = lower_bound(year, year+m, t) - year;
            int ans = t - a[pos];
            if(ans < 0)
                printf("0\n");
            else
                printf("%d\n", ans);
        }
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值