Submission #755234

#TimeUsernameProblemLanguageResultExecution timeMemory
755234Ahmed57Street Lamps (APIO19_street_lamps)C++17
0 / 100
31 ms43336 KiB
#include <bits/stdc++.h> using namespace std; const int N = 3e5+10; vector<int> node[N], bit[N]; int 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) { 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 q; signed 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 s;cin>>s;s = " "+s; int lol[n+1] = {0}; set<int> ind; ind.insert(0);ind.insert(n+1); for(int i = 1;i<=n;i++){ lol[i] = s[i]-'0'; if(!lol[i])ind.insert(i); } int que[q+1][3]; int xd[q+1][2]; int ans[q+1] = {0}; for(int i = 1;i<=q;i++){ string ty;cin>>ty; if(ty[0]=='t'){ int x;cin>>x; lol[x]^=1; if(lol[x])ind.erase(ind.find(x)); else ind.insert(x); auto it = ind.lower_bound(x+1); int r = *it-1; it--; if(*it==x)it--; int l = *it+1; fakeinc(l,x,x,r); que[i][0] = 0; que[i][1] = l; que[i][2] = r; xd[i][0] = x; xd[i][1] = (lol[i]?-i:i); }else{ int a,b;cin>>a>>b; b--; que[i][0] = 1; que[i][1] = a; que[i][2] = b; if(*ind.lower_bound(a)>b){ ans[i]+=i; } } } compress(); for(int i = 1;i<=q;i++){ if(que[i][0]==0){ inc(que[i][1],xd[i][0],xd[i][0],que[i][2],xd[i][1]); }else{ cout<<ans[i]+get(que[i][1],que[i][2])<<endl; } } return 0; }

Compilation message (stderr)

street_lamps.cpp: In function 'void fakeup(int, int)':
street_lamps.cpp:7:9: warning: statement has no effect [-Wunused-value]
    7 |     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:11:9: warning: statement has no effect [-Wunused-value]
   11 |     for(x; x <= n; x += x & -x) {
      |         ^
street_lamps.cpp:12:90: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 |         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:19:9: warning: statement has no effect [-Wunused-value]
   19 |     for(x; x; x -= x & -x) {
      |         ^
street_lamps.cpp: In function 'int main()':
street_lamps.cpp:50:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   50 |         freopen ("task.inp", "r", stdin);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
street_lamps.cpp:51:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   51 |         freopen ("task.out", "w", stdout);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
street_lamps.cpp:54:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   54 |         freopen (task".inp", "r", stdin);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
street_lamps.cpp:55:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   55 |         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...