Submission #708112

#TimeUsernameProblemLanguageResultExecution timeMemory
708112swagchickentrapezoid (balkan11_trapezoid)C++14
40 / 100
329 ms43572 KiB
#include <iostream> #include <tuple> #include <cmath> #include <string> #include <cstring> #include <vector> #include <deque> #include <queue> #include <stack> #include <random> #include <map> #include <unordered_map> #include <set> #include <unordered_set> #include <algorithm> #include <vector> #include <fstream> #include <iomanip> #include <ctime> #include <cctype> #include <climits> #include <chrono> using namespace std; typedef long long ll; 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-12; template<class T> class FenwickTree { private: vector<T> ft; public: FenwickTree(int m) { ft.assign(m + 1, 0); } int LSOne(int x) { return x & (-x); } T RMQ(int j) { // this allows array to be 0 indexed while ft is 1 indexed j++; int maxv = 0; for(; j > 0; j -= LSOne(j)) { maxv = max(maxv, ft[j]); } return maxv; } void update(int i, T v) { i++; for(; i < ft.size(); i += LSOne(i)) { ft[i] = max(ft[i], v); } } }; vector<pii> queries(210000, {-1e9, -1}); vector<pii> updates(210000, {-1e9, -1}); 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 int n; cin >> n; vector<piiii> trap(n); set<int> topv, botv; map<int, int> topcmp; map<int, int> botcmp; FOR(i,0,n) { cin >> trap[i].ff.ff >> trap[i].ff.ss >> trap[i].ss.ff >> trap[i].ss.ss; topv.insert(trap[i].ff.ff); topv.insert(trap[i].ff.ss); botv.insert(trap[i].ss.ff); botv.insert(trap[i].ss.ss); } int cnt = 0; for(int v : topv) { topcmp[v] = cnt; cnt++; } cnt = 0; for(int v : botv) { botcmp[v] = cnt; cnt++; } FOR(i,0,n) { queries[topcmp[trap[i].ff.ff]] = {botcmp[trap[i].ss.ff], i}; } FenwickTree<int> st(210000); FOR(i,0,210000) { if(queries[i].ff != -1e9) { int curr = st.RMQ(queries[i].ff) + 1; int idx = queries[i].ss; updates[topcmp[trap[idx].ff.ss]] = {curr , idx}; } if(updates[i].ff != -1e9) { int idx = updates[i].ss; int curr = updates[i].ff; st.update(botcmp[trap[idx].ss.ss], curr); } } int ans = st.RMQ(210000); cout << ans << " " << -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(); }

Compilation message (stderr)

trapezoid.cpp: In instantiation of 'void FenwickTree<T>::update(int, T) [with T = int]':
trapezoid.cpp:180:48:   required from here
trapezoid.cpp:120:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  120 |             for(; i < ft.size(); i += LSOne(i)) {
      |                   ~~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...