QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#97753 | #6192. Interval Problem | cardinal_city | RE | 3ms | 4408kb | C++20 | 3.3kb | 2023-04-18 07:50:42 | 2023-04-18 07:50:46 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector< vector <int> > vvi;
typedef pair<int, int> pii;
typedef pair < pair < int, int >, int > piii;
typedef pair < pair <int, int > , pair <int, int> > piiii;
typedef pair<ll, ll> pll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
#define FOR(i,a,b) for(int i = a; i < b; i ++)
#define RFOR(i,a,b) for(int i = a-1; i >= b; i --)
#define all(a) a.begin(), a.end()
#define endl '\n';
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
template <typename T>
void pr(vector<T> &v) {
FOR(i, 0, sz(v)) cout << v[i] << " ";
cout << endl;
}
template <typename T>
void pr(vector<vector<T> > &v) {
FOR(i, 0, sz(v)) { pr(v[i]); }
}
template <typename T>
void re(T &x) {
cin >> x;
}
template <typename T>
void re(vector<T> &a) {
FOR(i, 0, sz(a)) re(a[i]);
}
template <class Arg, class... Args>
void re(Arg &first, Args &... rest) {
re(first);
re(rest...);
}
template <typename T>
void pr(T x) {
cout << x << endl;
}
template <class Arg, class... Args>
void pr(const Arg &first, const Args &... rest) {
cout << first << " ";
pr(rest...);
cout << endl;
}
void ps() { cout << endl; }
template<class T, class... Ts>
void ps(const T& t, const Ts&... ts) {
cout << t; if (sizeof...(ts)) cout << " "; ps(ts...);
}
const ll MOD = 998244353;
#define inf 1e18;
#define INF INT_MAX
long double PI = 4*atan(1);
long double eps = 1e-16;
int MAXN = 100005;
vector<pii> ivs(MAXN);
vector<ll> ans(MAXN);
int n;
void solve(int n) {
vi p(2*n+1);
vi d(2*n+1);
vector<ll> sum(2*n+1);
vi numc(2 * n + 1);
vi lft(2 * n + 1, 1e8);
FOR(i,0,n) {
numc[ivs[i].ss]++;
lft[ivs[i].ss] = ivs[i].ff;
}
FOR(i,1,2*n + 1) numc[i] += numc[i-1];
RFOR(i,2*n, 1) lft[i] = min(lft[i], lft[i+1]);
FOR(i,1, 2 * n + 1) {
if(lft[i] >= i) {
p[i] = i;
d[i] = 0;
sum[i] = 0;
} else {
p[i] = p[lft[i]];
d[i] = d[lft[i]] + 1;
sum[i] = sum[lft[i]] + numc[i];
}
}
FOR(i,0,n) {
int l = ivs[i].ff;
int par = p[l];
ans[i] += sum[l] - ((ll) d[l] + 1) * (numc[par]);
}
}
int main() {
auto start = chrono::high_resolution_clock::now();
// ios_base::sync_with_stdio(0);cin.tie(0);
//ofstream cout("output.txt");
//ifstream cin("input.txt");
#ifdef DEBUG
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
cin >> n;
ivs.resize(n);
FOR(i,0,n) {
int l,r; cin >> l >> r;
ivs[i] = {l,r};
}
solve(n);
FOR(i,0,n) {
pii nw = {2 *n + 1 - ivs[i].ss, 2 * n + 1 - ivs[i].ff};
ivs[i] = nw;
}
solve(n);
FOR(i,0,n) {
cout << ans[i] + n - 1 << endl;
}
// auto stop = chrono::high_resolution_clock::now();
// auto duration = chrono::duration_cast<chrono::microseconds>(stop - start);
// cout << duration.count() << endl;
//cin.close();
//cout.close();
}
详细
Test #1:
score: 100
Accepted
time: 3ms
memory: 4408kb
input:
5 2 3 6 7 1 9 5 10 4 8
output:
7 5 4 5 5
result:
ok 5 number(s): "7 5 4 5 5"
Test #2:
score: -100
Runtime Error
input:
200000 342504 342505 248314 248317 259328 259334 234817 234821 225726 225732 371424 371425 260562 260565 34752 34753 132098 132100 262130 262134 7254 7255 228491 228492 43488 43492 188408 188410 11691 11692 350334 350335 327350 327352 360684 360685 182051 182052 72131 72135 194666 194668 61303 61313...