QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#335805#4077. 뚫기tuanlinh1230 1ms3584kbC++203.6kb2024-02-23 23:41:392024-02-23 23:41:39

Judging History

你现在查看的是最新测评结果

  • [2024-02-23 23:41:39]
  • 评测
  • 测评结果:0
  • 用时:1ms
  • 内存:3584kb
  • [2024-02-23 23:41:39]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define pll pair<ll, ll>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ld long double
using namespace std;

const ll inf=1e18;
struct SegTree
{
    struct Node
    {
        ll lzs=0;
        pll Min={0, 0}, lzm={inf, 0};
        Node(ll type=0) {if (type) Min.fi=inf;}

        Node operator + (const Node &o) const
        {
            Node ans; 
            ans.Min=min(Min, o.Min);
            return ans;
        }

        void act(ll ad, pll mi)
        {
            Min.fi+=ad, Min=min(Min, mi);
            lzs+=ad, lzm.fi+=ad, lzm=min(lzm, mi);
        }
    };

    ll n;
    vector <Node> St;
    SegTree (ll n): n(n) {St.resize(n*4+1);}
    
    void Move(ll i)
    {
        St[i*2].act(St[i].lzs, St[i].lzm);
        St[i*2+1].act(St[i].lzs, St[i].lzm);
        St[i].lzs=0, St[i].lzm={inf, 0};
    }

    void update(ll i, ll Start, ll End, ll l, ll r, ll ad, pll mi)
    {
        if (Start>r || End<l) return;
        if (Start>=l && End<=r) {St[i].act(ad, mi); return;}
        ll mid=(Start+End)/2; Move(i);
        if (l<=mid) update(i*2, Start, mid, l, r, ad, mi);
        if (r>=mid+1) update(i*2+1, mid+1, End, l, r, ad, mi);
        St[i]=St[i*2]+St[i*2+1];
    }
    void update(ll l, ll r, ll ad, pll mi) {update(1, 1, n, l, r, ad, mi);}

    Node query(ll i, ll Start, ll End, ll l, ll r)
    {
        if (Start>r || End<l) return Node(1);
        if (Start>=l && End<=r) return St[i];
        ll mid=(Start+End)/2; Move(i);
        if (l>mid) return query(i*2+1, mid+1, End, l, r);
        if (r<mid+1) return query(i*2, Start, mid, l, r);
        return query(i*2, Start, mid, l, r)+query(i*2+1, mid+1, End, l, r);
    }
    Node query(ll l, ll r) {return query(1, 1, n, l, r);}
};

ll n, m, l[10005], r[10005];
void init(int N, int M, vector <int> L, vector <int> R)
{
    n=N, m=M;
    for (ll i=0; i<n; i++)
        l[i]=L[i], r[i]=R[i];
    //compress numbers
    {
        vector <ll> num; num.pb(0);
        for (ll i=0; i<n; i++)
            num.pb(l[i]), num.pb(r[i]), num.pb(r[i]+1);
        sort(num.begin(), num.end());
        num.resize(unique(num.begin(), num.end())-num.begin());
        for (ll i=0; i<n; i++)
        {
            l[i]=lower_bound(num.begin(), num.end(), l[i])-num.begin()+1;
            r[i]=lower_bound(num.begin(), num.end(), r[i])-num.begin()+1;
        }
        m=num.size();
    }
    auto Try=[&](ll A, ll B)
    {
        SegTree S(m);
        for (ll i=0; i<n; i++)
        {
            S.update(l[i], r[i], B, {inf, 0});
            SegTree::Node best=S.query(1, m); 
            S.update(1, m, 0, {best.Min.fi+A, best.Min.se+1});
        }
        ll cost, a, b;
        tie(cost, a)=S.query(1, m).Min, b=(cost-a*A)/B;
        return mp(a, b);
    };
}

ll minimize(int A, int B)
{
    SegTree S(m);
    for (ll i=0; i<n; i++)
    {
        S.update(l[i], r[i], B, {inf, 0});
        SegTree::Node best=S.query(1, m); 
        S.update(1, m, 0, {best.Min.fi+A, best.Min.se+1});
    }
    return S.query(1, m).Min.fi;
}

// int main()
// {
//     ios_base::sync_with_stdio(0);
//     cin.tie(0); cout.tie(0);
//     freopen("input.txt", "r", stdin);
//     freopen("output.txt", "w", stdout);
//     ll n, m, q; cin >> n >> m >> q;
//     int l[n], r[n];
//     for (ll i=0; i<n; i++)
//         cin >> l[i] >> r[i];
//     init(n, m, l, r);
//     for (ll i=0; i<q; i++)
//     {
//         ll A, B; cin >> A >> B;
//         cout << minimize(A, B) << "\n";
//     }
// }

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3584kb

input:

6 2 1
1 1
0 1
0 0
0 1
1 1
0 1
724642704 32998300

output:

0

result:

wrong answer 1st lines differ - expected: '131993200', found: '0'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Time Limit Exceeded

Test #60:

score: 0
Time Limit Exceeded

input:

500 10 1000000
2 9
2 7
3 6
1 6
3 5
0 5
3 4
6 8
4 8
1 6
1 5
6 7
7 7
6 9
0 7
4 5
0 6
0 2
4 6
0 6
1 7
2 8
0 9
0 9
0 9
0 7
3 6
8 8
2 4
4 4
0 5
2 5
1 6
0 9
2 7
0 8
9 9
1 4
0 9
2 4
1 9
2 8
2 6
0 4
5 9
4 5
3 9
2 6
1 9
0 6
6 8
2 9
4 9
7 9
2 7
1 5
1 8
0 6
0 9
2 9
3 9
0 2
4 4
5 9
4 7
8 9
4 9
1 8
3 8
2 9
6 6
3...

output:

Unauthorized output

result:


Subtask #4:

score: 0
Skipped

Dependency #3:

0%

Subtask #5:

score: 0
Skipped

Dependency #1:

0%