Submission #753111

#TimeUsernameProblemLanguageResultExecution timeMemory
753111minhnhatnoePilot (NOI19_pilot)C++14
89 / 100
1081 ms34244 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll cresult = 0; vector<bool> act; set<pair<int, int>> s; ll calcpair(ll len){ return len*(len+1)/2; } ll calcpair(pair<int, int> se){ return calcpair(se.second - se.first + 1); } void insert(int pos){ act[pos] = true; cresult += calcpair(1); set<pair<int, int>>::iterator it1, it2; it2 = s.emplace(pos, pos).first; if (pos && act[pos-1]){ it1 = prev(it2); cresult -= calcpair(*it1) + calcpair(*it2); pair<int, int> nxt(it1->first, it2->second); s.erase(it1), s.erase(it2); it1 = s.insert(nxt).first; cresult += calcpair(nxt); } else it1 = it2; if (pos != act.size()-1 && act[pos+1]){ it2 = next(it1); cresult -= calcpair(*it1) + calcpair(*it2); pair<int, int> nxt(it1->first, it2->second); s.erase(it1), s.erase(it2); it1 = s.insert(nxt).first; cresult += calcpair(nxt); } } signed main(){ cin.tie(0)->sync_with_stdio(0); int n, q; cin >> n >> q; act.resize(n); vector<pair<int, int>> a(n), b(q); for (int i=0; i<n; i++){ cin >> a[i].first; a[i].second = i; } for (int i=0; i<q; i++){ cin >> b[i].first; b[i].second = i; } vector<ll> result(q); sort(a.begin(), a.end()), sort(b.begin(), b.end()); for (int i=0, aptr=0; i<q; i++){ while (aptr < a.size() && a[aptr].first <= b[i].first){ insert(a[aptr++].second); } result[b[i].second] = cresult; } for (int i=0; i<q; i++){ cout << result[i] << "\n"; } }

Compilation message (stderr)

pilot.cpp: In function 'void insert(int)':
pilot.cpp:29:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<bool>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |     if (pos != act.size()-1 && act[pos+1]){
      |         ~~~~^~~~~~~~~~~~~~~
pilot.cpp: In function 'int main()':
pilot.cpp:54:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |         while (aptr < a.size() && a[aptr].first <= b[i].first){
      |                ~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...