Участник:ZhenyaStrelkova/ACTIV

Материал из DISCOPAL
Перейти к: навигация, поиск

https://www.spoj.com/problems/ACTIV/

#include <iostream>
#include <algorithm>
#include <utility>
#include <iomanip>
 
using namespace std;
 
const int maximum = 100007;
const int mod = 1e8;
 
 
 
bool comparator(pair<int, int> left, pair<int, int> right) {
    return left.second < right.second;
}
 
int main() {
    pair<int, int> a[maximum];
    int n;
    int result[maximum];
    cin >> n;
    while (n != -1) {
        for (int i = 1; i <= n; i++) {
            cin >> a[i].first >> a[i].second;
        }
        sort(a + 1, a + n + 1, comparator);
        result[0] = 1;
        for (int i = 1; i <= n; i++) {
            result[i] = result[i - 1];
            auto val = make_pair(0, a[i].first);
            auto next_pos = upper_bound(a, a + n + 1, val, comparator) - a - 1;
            result[i] += result[next_pos];
            result[i] %= mod;
        }
        result[n] += mod - 1;
        result[n] %= mod;
        cout << setfill('0') << setw(8) << result[n] << endl;
        cin >> n;
    }
    return 0;
}