제출 #739194

#제출 시각아이디문제언어결과실행 시간메모리
739194nguyentunglam가로등 (APIO19_street_lamps)C++17
100 / 100
2400 ms109924 KiB
#include<bits/stdc++.h> #define fi first #define se second #define endl "\n" #define ii pair<int, int> using namespace std; const int N = 3e5 + 10; int a[N], ans[N]; int n, q; tuple<int, int, int> query[N]; pair<int, int> tt[N]; vector<int> node[N], bit[N]; void fakeup (int x, int y) { for(x; x <= n; x += x & -x) node[x].push_back(y); } void up(int x, int yy, int val) { if (yy > n) return; for(x; x <= n; x += x & -x) { for(int y = upper_bound(node[x].begin(), node[x].end(), yy) - node[x].begin(); y <= node[x].size(); y += y & -y) { bit[x][y] += val; } } } int get(int x, int yy) { int ret = 0; for(x; x; x -= x & -x) { if (node[x].empty()) continue; for(int y = upper_bound(node[x].begin(), node[x].end(), yy) - node[x].begin(); y; y -= y & -y) { ret += bit[x][y]; } } return ret; } void compress() { for(int i = 1; i <= n; i++) { sort(node[i].begin(), node[i].end()); node[i].resize(unique(node[i].begin(), node[i].end()) - node[i].begin()); bit[i].resize(node[i].size() + 1); } } void fakeinc(int x, int y, int u, int v) { fakeup(x, y); fakeup(x, v + 1); fakeup(u + 1, y); fakeup(u + 1, v + 1); } void inc(int x, int y, int u, int v, int val) { up(x, y, val); up(x, v + 1, -val); up(u + 1, y, -val); up(u + 1, v + 1, val); } int main() { #define task "" cin.tie(0) -> sync_with_stdio(0); if (fopen ("task.inp", "r")) { freopen ("task.inp", "r", stdin); freopen ("task.out", "w", stdout); } if (fopen (task".inp", "r")) { freopen (task".inp", "r", stdin); freopen (task".out", "w", stdout); } cin >> n >> q; string str; cin >> str; str = " " + str; set<int> s = {0, n + 1}; for(int i = 1; i <= n; i++) { a[i] = str[i] - '0'; if (!a[i]) s.insert(i); } for(int timer = 1; timer <= q; timer++) { string ask; cin >> ask; if (ask[0] == 't') { int i; cin >> i; a[i] ^= 1; if (a[i]) s.erase(s.find(i)); else s.insert(i); auto it = s.upper_bound(i); int r = *it - 1; it--; if (*it == i) it--; int l = *it + 1; fakeinc(l, i, i, r); query[timer] = {0, l, r}; tt[timer].fi = i; tt[timer].se = a[i] ? -timer : timer; } else { int l, r; cin >> l >> r; r--; query[timer] = {1, l, r}; if (*s.lower_bound(l) > r) ans[timer] += timer; } } compress(); for(int timer = 1; timer <= q; timer++) { int type, l, r; tie(type, l, r) = query[timer]; if (type == 0) { int i, val; tie(i, val) = tt[timer]; inc(l, i, i, r, val); } else cout << get(l, r) + ans[timer] << endl; } }

컴파일 시 표준 에러 (stderr) 메시지

street_lamps.cpp: In function 'void fakeup(int, int)':
street_lamps.cpp:14:9: warning: statement has no effect [-Wunused-value]
   14 |     for(x; x <= n; x += x & -x) node[x].push_back(y);
      |         ^
street_lamps.cpp: In function 'void up(int, int, int)':
street_lamps.cpp:18:9: warning: statement has no effect [-Wunused-value]
   18 |     for(x; x <= n; x += x & -x) {
      |         ^
street_lamps.cpp:19:90: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 |         for(int y = upper_bound(node[x].begin(), node[x].end(), yy) - node[x].begin(); y <= node[x].size(); y += y & -y) {
      |                                                                                        ~~^~~~~~~~~~~~~~~~~
street_lamps.cpp: In function 'int get(int, int)':
street_lamps.cpp:26:9: warning: statement has no effect [-Wunused-value]
   26 |     for(x; x; x -= x & -x) {
      |         ^
street_lamps.cpp: In function 'int main()':
street_lamps.cpp:57:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   57 |         freopen ("task.inp", "r", stdin);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
street_lamps.cpp:58:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   58 |         freopen ("task.out", "w", stdout);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
street_lamps.cpp:61:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   61 |         freopen (task".inp", "r", stdin);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
street_lamps.cpp:62:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   62 |         freopen (task".out", "w", stdout);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#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...