QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#181997 | #4894. 学姐买瓜 | hos_lyric# | 0 | 0ms | 0kb | C++14 | 2.8kb | 2023-09-17 08:30:56 | 2024-07-04 02:01:19 |
answer
#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using Int = long long;
template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
#define COLOR(s) ("\x1b[" s "m")
int N, M;
vector<int> O, L, R;
namespace brute {
vector<int> run() {
vector<pair<pair<int, int>, int>> ps;
for (int i = 0; i < N; ++i) if (O[i] == 1) {
ps.emplace_back(make_pair(R[i], L[i]), i);
}
sort(ps.begin(), ps.end());
const int psLen = ps.size();
vector<int> ids(N, -1);
for (int x = 0; x < psLen; ++x) {
ids[ps[x].second] = x;
}
vector<int> on(psLen, 0);
vector<int> ans(N, 0);
for (int i = 0; i < N; ++i) {
if (O[i] == 1) {
on[ids[i]] = 1;
} else {
int now = L[i];
for (int x = 0; x < psLen; ++x) if (on[x]) {
if (now <= ps[x].first.second && ps[x].first.first <= R[i]) {
++ans[i];
now = ps[x].first.first;
}
}
}
}
return ans;
}
} // brute
namespace brute2 {
vector<int> run() {
vector<int> to(N + 1, N + 1);
vector<int> ans(N, 0);
for (int i = 0; i < N; ++i) {
if (O[i] == 1) {
for (int u = L[i]; u >= 0; --u) {
if (!chmin(to[u], R[i])) {
break;
}
}
} else {
for (int u = L[i]; u <= R[i]; u = to[u]) {
++ans[i];
}
--ans[i];
}
}
return ans;
}
} // brute2
int main() {
for (; ~scanf("%d%d", &N, &M); ) {
O.resize(N);
L.resize(N);
R.resize(N);
for (int i = 0; i < N; ++i) {
scanf("%d%d%d", &O[i], &L[i], &R[i]);
--L[i];
}
const auto ans = brute2::run();
for (int i = 0; i < N; ++i) if (O[i] == 2) {
printf("%d\n", ans[i]);
}
cerr<<"========"<<endl;
}
return 0;
}
详细
Subtask #1:
score: 0
Time Limit Exceeded
Test #1:
score: 0
Time Limit Exceeded
input:
11 13 2 4 4 1 11 12 1 1 5 1 2 3 1 2 10 2 2 8 1 6 6 2 2 10 1 6 11 2 2 3 2 2 13
output:
result:
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #2:
0%