Submission #237694

# Submission time Handle Problem Language Result Execution time Memory
237694 2020-06-08T10:46:19 Z Half Lasers (NOI19_lasers) C++14
10 / 100
121 ms 5196 KB
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pi;
typedef long long ll;

#define loop(i,a,b) for (int i = a; i <= b; i++)

#define INF ((unsigned) ~0)
#define F first
#define S second
#define PB push_back
#define MP make_pair

const int MXL = 1000000000;
int L, R, sol;
set<pi> rgs;

void rUp(int l, int r){
    if(r <= l)
        return;
    if(rgs.size() == 0){
        rgs.insert(MP(l, r));
        sol += r - l;
        return;
    }
    set<pi>::iterator it = rgs.upper_bound(MP(l, -1));
    pi pa, pb;
    if(it == rgs.end()){
        it--;
        pa = *it;
        sol += max(r - l - min(pa.S - l, r - l), 0);
        if(pa.S >= l && pa.S < r){
            rgs.erase(pa);
            rgs.insert(MP(pa.F, r));
        }else if(pa.S < l){
            rgs.insert(MP(l, r));
        }
        return;
    }
    if(it == rgs.begin()){
        pb = *it;
        sol += r - l - max(min(r - pb.F, r - l), 0);
        if(r >= pb.F && l < pb.F){
            rgs.erase(pb);
            rgs.insert(MP(l, pb.S));
        }else if(r < pb.F){
            rgs.insert(MP(l, r));
        }
        return;
    }
    pa = *(--it);
    pb = *(++it);
    sol += max(r - l - max(pa.S - l, 0) - max(r - pb.F, 0), 0);
    if(pa.S >= l && r >= pb.F){
        rgs.erase(pa);
        rgs.erase(pb);
        rgs.insert(MP(pa.F, pb.S));
    }else if(pa.S >= l && pa.S < r){
        rgs.erase(pa);
        rgs.insert(MP(pa.F, r));
    }else if(r >= pb.F && l < pb.F){
        rgs.erase(pb);
        rgs.insert(MP(l, pb.S));
    }else if(l > pa.S && r < pb.F){
        rgs.insert(MP(l, r));
    }
    return;
}

int main(){
    sol = 0;
    cin >> L >> R;
    for(int k = 0; k < R; k++){
        int X, gp = L, sm = 0;
        cin >> X;
        int a[500000];
        for(int i = 0; i < X; i++){
            cin >> a[i];
            gp -= a[i];
        }
        for(int i = 0; i < X; i++){
            rUp(sm + gp, sm + a[i]);
            sm += a[i];
        }
        /*for(set<pi>::iterator it = rgs.begin(); it != rgs.end(); it++){
            cout << "\n" << it->F << " " << it->S << "\n\n";
        }*/
    }
    cout << sol << "\n";
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 4 ms 256 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 4 ms 256 KB Output is correct
7 Correct 5 ms 512 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 4 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 4 ms 256 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 4 ms 256 KB Output is correct
7 Correct 5 ms 512 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 4 ms 256 KB Output is correct
11 Incorrect 5 ms 384 KB Output isn't correct
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 121 ms 5196 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 121 ms 5196 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 4 ms 256 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 4 ms 256 KB Output is correct
7 Correct 5 ms 512 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 4 ms 256 KB Output is correct
11 Incorrect 5 ms 384 KB Output isn't correct
12 Halted 0 ms 0 KB -