QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#428975#6531. Base Station Constructiondnialh#WA 64ms6396kbC++232.4kb2024-06-01 23:38:332024-06-01 23:38:34

Judging History

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

  • [2024-06-01 23:38:34]
  • 评测
  • 测评结果:WA
  • 用时:64ms
  • 内存:6396kb
  • [2024-06-01 23:38:33]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define f first
#define s second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define sz(v) (int)v.size()
#define sq(a) ((a)*(a))

#define per(i,a,b) for (int i = (b)-1; i >= a; i--)
#define rep(i,a,b) for (int i=a; i<b; i++)

#define FOR(i,a,b) for (int i=a; i<b; i++)
#define F0R(i,a) for (int i=0; i<a; i++)
#define ROF(i,a,b) for (int i = (b)-1; i >= a; i--)
#define R0F(i,a) for (int i = (a)-1; i >= 0; i--)

#define FAST ios::sync_with_stdio(0); cin.tie(0);
#define finish(x) return cout << x << endl, 0;
#define dbg(x) cerr << ">>> " << #x << " = " << x << endl;
#define _ << " _ " <<

#define ll long long

template<class T> bool ckmin(T&a, T&b) { bool B = a > b; a = min(a,b); return B; }
template<class T> bool ckmax(T&a, T&b) { bool B = a < b; a = max(a,b); return B; }

typedef long double ld;
typedef pair<int,int> pi;
typedef pair<ld,ld> pld;
typedef complex<ld> cd;

typedef vector<int> vi;
typedef vector<ld> vld;
typedef vector<vector<int>> vvi;


const ld PI = acos(-1.0);
const ld EPS = 1e-7;
const int MOD = 998244353;


struct Tree {
	typedef ll T;
	static constexpr T unit = 1e17;
	T f(T a, T b) { return min(a, b); } // (any associative fn)
	vector<T> s; int n;
	Tree(int n = 0, T def = unit) : s(2*n, def), n(n) {}
	void update(int pos, T val) {
		for (s[pos += n] = val; pos /= 2;)
			s[pos] = f(s[pos * 2], s[pos * 2 + 1]);
	}
	T query(int b, int e) { // query [b, e)
		T ra = unit, rb = unit;
		for (b += n, e += n; b < e; b /= 2, e /= 2) {
			if (b % 2) ra = f(ra, s[b++]);
			if (e % 2) rb = f(s[--e], rb);
		}
		return f(ra, rb);
	}
};

void solve() {
  int n;
  cin >> n;

  vi a(n);
  F0R(i, n) {
    cin >> a[i];
  }

  vi rev(n + 1, 0);
  int m; cin >> m;

  F0R(i, m) {
    int li, ri;
    cin >> li >> ri;
    rev[ri] = max(rev[ri], li);
  }

  F0R(i, n){
    rev[i + 1] = max(rev[i + 1], rev[i]);
  }

  vector<long long> dp(n + 1, 0);
  Tree seg(n + 1, 1e17);
  seg.update(0, 0);
  FOR(i, 1, n + 1){
    ll base = a[i - 1] + seg.query(rev[i - 1], i);
    // cout << i << " " << rev[i - 1] << " " << base << '\n';
    dp[i] = base;
    seg.update(i, base);
  }

  cout << dp[n] << '\n';
}

int32_t main() { FAST
  int t;
  cin >> t;

  while (t--) {
    solve();
  }

  return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3872kb

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: 64ms
memory: 6396kb

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:

141
88
59
126
303
141
45
170
159
139
222
194
217
147
230
93
287
89
124
130
148
125
100
193
228
111
239
303
236
150
177
57
59
38
90
128
83
160
108
62
35
122
156
81
115
229
110
242
126
28
210
86
311
244
262
162
302
177
93
238
30
129
75
109
96
179
81
224
142
172
119
111
215
247
301
121
120
56
213
118
3...

result:

wrong answer 2nd numbers differ - expected: '48', found: '88'