QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#767553#6531. Base Station ConstructiondiguoWA 106ms43940kbC++202.9kb2024-11-20 21:15:002024-11-20 21:15:06

Judging History

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

  • [2024-11-20 21:15:06]
  • 评测
  • 测评结果:WA
  • 用时:106ms
  • 内存:43940kb
  • [2024-11-20 21:15:00]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define all(x, y) x.begin() + y, x.end()
#define mkp make_pair
#define pii pair<int, int>
#define pil pair<int, long long>
#define pli pair<long long, int>
#define pll pair<long long, long long>
#define ll long long
#define ull unsigned long long
#define pb push_back
#define rep(name, base, limit) for(int name = base; name <= limit; ++name)
#define per(name, base, limit) for(int name = base; name >= limit; --name)
#define lowbit(x) ((x) & -(x))
#define ls(p) ((p) << 1)
#define rs(p) ((p) << 1 | 1)
const int INF = 0x3f3f3f3f;
const long long LNF = 0x3f3f3f3f3f3f3f3f;

inline long long read()
{
    long long x=0,f=1;char ch=getchar();
    while (ch<'0'||ch>'9'){if (ch=='-') f=-1;ch=getchar();}
    while (ch>='0'&&ch<='9'){x=x*10+ch-48;ch=getchar();}
    return x*f;
} 

/*
f[i]表示包含i以及其i的左侧的区间内, 最小的cost
设j为i左侧第一个不包含i的r, k为i左侧的第一个包含i的区间的l
如不存在区间, k = 0
对j和k分类讨论
对于j < k的情况, f[i] = min(f[j] + min(w[k ~ i]));
对于j >= k的情况, f[i] = f[j]
*/
const int LGN = 500000;
int lg2[LGN + 1];
//don't forget init value of log2 and calculate function
void lginit()
{
    rep(i, 2, LGN) lg2[i] = lg2[i / 2] + 1;
}
struct ST
{
    vector<vector<ll>> st;
    ll cal(ll x, ll y)
    {
        ll ret = min(x, y);
        return ret;
    }
    void init(vector<ll> a, int n)
    {
        st.resize(n + 1);
        rep(i, 0, n) st[i].resize(31), st[i][0] = a[i];
        rep(i, 1, 20) for (int j = 1; j + (1 << i) - 1 <= n; ++j)
        st[j][i] = cal(st[j][i - 1], st[j + (1 << (i - 1))][i - 1]);
    }
    ll query(int l, int r)
    {
        int s = lg2[r - l + 1];
        return cal(st[l][s], st[r - (1 << s) + 1][s]);
    }
};

void solve()
{
    int n = read();
    vector<ll> a(n + 1);
    rep(i, 1, n) a[i] = read();
    ST st;
    st.init(a, n);
    vector<ll> f(n + 1);
    int m = read();
    vector vl(n + 1, vector<int>()), vr(n + 1, vector<int>());
    vector<int> l(m + 1), r(m + 1);
    rep(i, 1, m)
    {
        l[i] = read(), r[i] = read();
        vl[l[i]].pb(i), vr[r[i]].pb(i);
    }
    int lstr = 0;
    multiset<int> lstl;
    // set<int> now;
    rep(i, 1, n)
    {
        for (auto x: vl[i])
        {
            // now.insert(x);
            lstl.insert(l[x]);
        }
        if (lstl.empty()) f[i] = f[lstr];
        else
        {
            int k = *lstl.rbegin();
            if (k <= lstr) f[i] = f[lstr];
            else f[i] = f[lstr] + st.query(k, i);
        }
        for (auto x: vr[i])
        {
            lstr = i;
            lstl.erase(lstl.lower_bound(l[x]));
        }
    }
    cout << f[n];
}

int main()
{
    lginit();
    int t = read();
    while (t--)
    {
        solve();
        if (t) putchar('\n');
    }
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 5488kb

input:

2
5
3 2 4 1 100
3
1 3
2 4
5 5
5
7 3 4 2 2
3
1 4
2 3
4 5

output:

102
5

result:

ok 2 number(s): "102 5"

Test #2:

score: -100
Wrong Answer
time: 106ms
memory: 43940kb

input:

6201
12
88 78 46 95 84 98 55 3 68 42 6 18
19
6 9
10 11
12 12
8 11
8 12
2 3
2 3
1 5
9 9
7 8
6 11
2 4
12 12
2 4
2 9
7 10
8 8
1 7
6 11
5
76 27 48 66 61
2
1 4
3 5
8
64 81 20 6 86 9 4 55
1
7 7
9
1 43 18 81 11 22 9 61 83
14
5 6
2 6
5 8
1 4
9 9
9 9
7 7
2 5
8 9
5 6
4 8
5 8
9 9
6 6
10
66 41 84 7 80 31 22 96 ...

output:

232
48
4
267
303
141
23
170
159
192
265
243
267
127
268
93
411
89
138
130
294
27
1
193
359
93
239
312
378
150
177
57
46
18
91
79
83
160
196
62
35
122
285
275
115
277
61
394
252
306
383
86
399
244
288
87
302
81
223
173
30
129
145
128
126
179
81
312
142
277
143
111
235
247
211
53
91
17
213
101
482
176...

result:

wrong answer 1st numbers differ - expected: '141', found: '232'