Submission #37599

#TimeUsernameProblemLanguageResultExecution timeMemory
37599szawinistrapezoid (balkan11_trapezoid)C++14
100 / 100
359 ms57520 KiB
#include <cstdio> #include <algorithm> #include <vector> #include <climits> #include <unordered_map> using namespace std; const int N = 1 << 19, MOD = 30013; struct query { int r, type, idx; bool operator<(const query& rhs) const { return type < rhs.type; } }; struct pr { int first, second; }; int n, a[N], b[N], c[N], d[N], dp[N], f[N]; vector<query> segs[N]; pr ans = {INT_MIN, 0}; pr merge(pr p1, pr p2) { if(p1.first > p2.first) return p1; else if(p2.first > p1.first) return p2; else return {p1.first, (p1.second + p2.second) % MOD}; } pr t[2*N]; void update(int i, int sz, int cnt) { i += N; t[i] = merge({sz, cnt}, t[i]); for(i >>= 1; i >= 1; i >>= 1) t[i] = merge(t[i<<1], t[i<<1|1]); } pr allahu(int l, int r) { // [) pr res = {INT_MIN, 0}; for(l += N, r += N; l < r; l >>= 1, r >>= 1) { if(l & 1) res = merge(res, t[l++]); if(r & 1) res = merge(res, t[--r]); } return res; } int main() { scanf("%d", &n); for(int i = 1; i <= n; i++) scanf("%d %d %d %d", &a[i], &b[i], &c[i], &d[i]); vector<int> cc; unordered_map<int, int> pos; for(int i = 1; i <= n; i++) { cc.push_back(a[i]); cc.push_back(b[i]); cc.push_back(c[i]); cc.push_back(d[i]); } sort(cc.begin(), cc.end()); cc.resize(distance(cc.begin(), unique(cc.begin(), cc.end()))); for(int i = 0; i < cc.size(); i++) pos[cc[i]] = i+1; for(int i = 1; i <= n; i++) { a[i] = pos[a[i]]; b[i] = pos[b[i]]; c[i] = pos[c[i]]; d[i] = pos[d[i]]; } for(int i = 1; i <= n; i++) { segs[a[i]].push_back({c[i], 0, i}); segs[b[i]].push_back({d[i], 1, i}); } fill(t, t+2*N, (pr) {INT_MIN, 0}); update(0, 0, 1); for(int l = 1; l < N; l++) { sort(segs[l].begin(), segs[l].end()); for(query qq: segs[l]) { if(!qq.type) { pr res = allahu(0, c[qq.idx]); dp[qq.idx] = res.first; f[qq.idx] = res.second; ++dp[qq.idx]; ans = merge(ans, {dp[qq.idx], f[qq.idx]}); } else { update(d[qq.idx], dp[qq.idx], f[qq.idx]); } } } printf("%d %d", ans.first, ans.second); }

Compilation message (stderr)

trapezoid.cpp: In function 'int main()':
trapezoid.cpp:58:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < cc.size(); i++) pos[cc[i]] = i+1;
                   ^
trapezoid.cpp:46:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
                 ^
trapezoid.cpp:47:78: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i = 1; i <= n; i++) scanf("%d %d %d %d", &a[i], &b[i], &c[i], &d[i]);
                                                                              ^
#Verdict Execution timeMemoryGrader output
Fetching results...