Submission #1230740

#TimeUsernameProblemLanguageResultExecution timeMemory
1230740phoenix_새로운 문제 (POI11_met)C++17
100 / 100
950 ms47376 KiB
#include <iostream> #include <iosfwd> #include <iomanip> #include <cstdio> #include <cstring> #include <cstdlib> #include <ctime> #include <cmath> #include <cassert> #include <cctype> #include <climits> #include <vector> #include <bitset> #include <set> #include <queue> #include <stack> #include <map> #include <deque> #include <string> #include <list> #include <iterator> #include <sstream> #include <complex> #include <fstream> #include <functional> #include <numeric> #include <utility> #include <algorithm> #include <chrono> #include <unordered_set> #include <unordered_map> #include <random> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; template<class T> using OrderedSet = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; // MACROS_BEGIN #define CLEAR() cerr << endl; #define LET(x, a) __typeof(a) x = a #define FOREACH(it, v) for (LET(it, (v).begin()); it != (v).end(); ++it) #define REPEAT(i, n) for (int i = 0; i < (n); ++i) // MACROS_END // GENERIC_UTILITIES_BEGIN // template <class T> inline int size(const T& c) {return (int) c.size();} inline long long two(int x) {return (1LL << (x));} vector<string> split(string s, string delim) { s += delim[0]; string tmp; vector<string> result; for (int i = 0; i < size(s); ++i) { if (delim.find(s[i]) == string::npos) { tmp.push_back(s[i]); } else { if (tmp != "") result.push_back(tmp); tmp.clear(); } } return result; } // GENERIC_UTILITIES_END // FAST_IO_BEGIN // FAST_IO_END // STANDARD_IO_BEGIN #ifndef USING_FAST_IO int readInt() {int N = -1; scanf("%d", &N); return N;} double readDouble() {double D; scanf("%lf", &D); return D;} string readString() {char buffer[1 << 20]; scanf("%s", buffer); return buffer;} long long readLongLong() {long long N = -1; scanf("%lld", &N); return N;} #endif // NOT DEFINED USING_FAST_IO // STANDARD_IO_END // OUTPUT_UTILITIES_BEGIN template <class A, class B> ostream& operator << (ostream& o, const pair<A, B>& p); template <class T> ostream& operator << (ostream& o, const vector<T>& v); template <class A, class B> ostream& operator << (ostream& o, const map<A, B>& m); template <class T> ostream& operator << (ostream& o, const set<T>& s); template <class T> ostream& operator << (ostream& o, const queue<T>& q); template <class T> ostream& operator << (ostream& o, const stack<T>& s); template <class A, class B> ostream& operator << (ostream& o, const pair<A, B>& p) { o << "(" << p.first << "," << p.second << ")"; return o; } template <class T> ostream& operator << (ostream& o, const vector<T>& v) { o << "{"; bool first = true; FOREACH(it, v) { if (!first) o << ","; first = false; o << *it; } return o << "}"; } template <class A, class B> ostream& operator << (ostream& o, const map<A, B>& m) { o << "{"; bool first = true; FOREACH(it, m) { if (!first) o << ","; first = false; o << *it; } return o << "}"; } template <class T> ostream& operator << (ostream& o, const set<T>& s) { o << "{"; bool first = true; FOREACH(it, s) { if (!first) o << ","; first = false; o << *it; } return o << "}"; } template <class T> ostream& operator << (ostream& o, const queue<T>& q) { o << "{"; bool first = true; queue<T> p = q; while (!p.empty()) { if (!first) o << ","; first = false; o << p.front(); p.pop(); } return o << "}"; } template <class T> ostream& operator << (ostream& o, const stack<T>& s) { o << "{"; bool first = true; stack<T> r = s; while (!r.empty()) { if (!first) o << ","; first = false; o << r.top(); r.pop(); } return o << "}"; } // OUTPUT_UTILITIES_END // DEBUGGING_UTILITIES_BEGIN // DEBUGGING SWITCH #define PHOENIX_DEBUG #ifdef PHOENIX_DEBUG #define DEBUG(...) __f(__LINE__, #__VA_ARGS__, __VA_ARGS__) template<typename Arg> void __print(const string& name, Arg&& arg) { cerr << "[" << name << ": " << arg << "]" << " "; } void __printLine(int line) { cerr << "LINE " << line << ": "; cerr << boolalpha; } template<typename Arg> void __g(vector<string>& names, int idx, Arg&& arg) { __print(names[idx], arg); } template<typename Arg, typename... Args> void __g(vector<string>& names, int idx, Arg&& arg, Args&&... args) { __g(names, idx, arg); __g(names, idx + 1, args...); } template <typename Arg> void __f(int line, const string& name, Arg&& arg) { __printLine(line); __print(name, arg); CLEAR(); } template <typename Arg, typename... Args> void __f(int line, const string& _names, Arg&& arg, Args&&... args) { __printLine(line); vector<string> names = split(_names, ", "); __g(names, 0, arg, args...); CLEAR(); } #else #define DEBUG(...) #endif // DEBUGGING_UTILITIES_END mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const double epsilon = 1e-8; const int infinite = 1000000000 + 5; // 2 * 10^9 const long long infiniteLL = 2000000000000000000LL; // 2 * 10^18 const long long modulo = 1000000007; struct FenwickTree { int N; vector<long long> tree; void initialize(int _N) { N = _N; tree.resize(N + 1, 0); } void update(int idx, long long v) { for (int x = idx + 1; x <= N; x += x & -x) { tree[x] += v; } } void rangeUpdate(int low, int high, long long val) { update(low, val); update(high + 1, -val); } long long query(int idx) { long long sum = 0; for (int x = idx + 1; x > 0; x -= x & -x) { sum += tree[x]; } return sum; } long long query(int low, int high) { return query(high) - query(low - 1); } }; struct Task { int N, M, K, Q; vector<int> requirement; vector< vector<int> > queries; vector< vector<int> > properties; vector< vector<int> > candidates; vector<int> L, R, answer; void readInput() { N = readInt(), M = readInt(); properties.resize(N); requirement.resize(N); for (int i = 0; i < M; ++i) { int x = readInt() - 1; properties[x].push_back(i); } for (int i = 0; i < N; ++i) { requirement[i] = readInt(); assert(requirement[i] <= 1000000000); } Q = readInt(); queries.resize(Q); for (int i = 0; i < Q; ++i) { int low = readInt() - 1, high = readInt() - 1, a = readInt(); queries[i] = {low, high, a}; } } void solve() { L.resize(N, 0); R.resize(N, Q - 1); answer.resize(N, -1); bool search = true; while (search) { search = false; candidates.clear(); candidates.resize(Q + 1); FenwickTree tree; tree.initialize(M); for (int i = 0; i < N; ++i) { if (L[i] <= R[i]) { search = true; int mid = (L[i] + R[i]) / 2; candidates[mid].push_back(i); } } for (int i = 0; i < Q; ++i) { int low = queries[i][0], high = queries[i][1], a = queries[i][2]; if (low > high) { tree.rangeUpdate(low, M - 1, a); tree.rangeUpdate(0, high, a); } else { tree.rangeUpdate(low, high, a); } for (int idx : candidates[i]) { long long sum = 0; for (int p : properties[idx]) { sum += tree.query(p); if (sum >= requirement[idx]) { break; } } if (sum >= requirement[idx]) { answer[idx] = i; R[idx] = i - 1; } else { L[idx] = i + 1; } if (L[idx] <= R[idx]) { search = true; } } } } for (int i = 0; i < N; ++i) { if (answer[i] == -1) { printf("NIE\n"); } else { printf("%d\n", answer[i] + 1); } } } void perform() { readInput(); solve(); } }; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); Task task; task.perform(); return 0; }

Compilation message (stderr)

met.cpp: In function 'int readInt()':
met.cpp:74:33: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   74 | int readInt() {int N = -1; scanf("%d", &N); return N;}
      |                            ~~~~~^~~~~~~~~~
met.cpp: In function 'double readDouble()':
met.cpp:75:37: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   75 | double readDouble() {double D; scanf("%lf", &D); return D;}
      |                                ~~~~~^~~~~~~~~~~
met.cpp: In function 'std::string readString()':
met.cpp:76:49: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   76 | string readString() {char buffer[1 << 20]; scanf("%s", buffer); return buffer;}
      |                                            ~~~~~^~~~~~~~~~~~~~
met.cpp: In function 'long long int readLongLong()':
met.cpp:77:50: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   77 | long long readLongLong() {long long N = -1; scanf("%lld", &N); return N;}
      |                                             ~~~~~^~~~~~~~~~~~
#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...