답안 #136752

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
136752 2019-07-26T08:13:29 Z KLPP 가로등 (APIO19_street_lamps) C++14
60 / 100
1879 ms 33388 KB
#include<bits/stdc++.h>

using namespace std;
typedef long long int lld;
typedef pair<lld,lld> pii;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define trav(a,v) for(auto a:v)
class ST{
  pii arr[1200000];
public:
  void build(int a, int b, int node){
    if(a==b){
      arr[node]=pii(0,0);
      return;
    }
    int mid=(a+b)/2;
    build(a,mid,2*node);
    build(mid+1,b,2*node+1);
    arr[node]=max(arr[2*node],arr[2*node+1]);
  }
  void update(int a, int b, int node, int pos, int val){
    if(pos<a || b<pos)return;
    if(a==b){
      arr[node]=pii(-1,val);
      return;
    }
    int mid=(a+b)/2;
    update(a,mid,2*node,pos,val);
    update(mid+1,b,2*node+1,pos,val);
    arr[node]=max(arr[2*node],arr[2*node+1]);
  }
  pii query(int a, int b, int node, int x, int y){
    if(b<x || y<a)return pii(-10,0);
    if(x<=a && b<=y)return arr[node];
    int mid=(a+b)/2;
    return max(query(a,mid,2*node,x,y),query(mid+1,b,2*node+1,x,y));
  }
  void print(int a, int b, int node){
    cout<<a<<" "<<b<<" "<<arr[node].first<<" "<<arr[node].second<<endl;
    if(a==b)return;
    int mid=(a+b)/2;
    print(a,mid,2*node);
    print(mid+1,b,2*node+1);
  }
};
int main(){
  int n,q;
  cin>>n>>q;
  string state;
  cin>>state;
  string type[q];
  int queries[q][2];
  rep(i,0,q){
    cin>>type[i];
    if(type[i]=="query"){
      cin>>queries[i][0]>>queries[i][1];
      queries[i][0]--;
      queries[i][1]-=2;
    }else{
      cin>>queries[i][0];
      queries[i][0]--;
    }
  }
  if(n<=100 && q<=100){
    vector<string> V;
    V.push_back(state);
    rep(i,0,q){
      
      if(type[i]=="query"){
	int ans=0;
	trav(a,V){
	  bool b=true;
	  rep(j,queries[i][0],queries[i][1]+1){
	    if(a[j]=='0')b=false;
	  }
	  ans+=b;
	  //cout<<a<<endl;
	}
	cout<<ans<<endl;
      }else{
	state[queries[i][0]]='0'+'1'-state[queries[i][0]];
      }
      V.push_back(state);
    }
    return 0;
  }
  bool tight=true;
  rep(i,0,q){
    if(type[i]=="query"){
      if(queries[i][1]!=queries[i][0])tight=false;
    }
  }
  if(tight){
    lld times[n];
    lld tot[n];
    rep(i,0,n){
      if(state[i]=='0')times[i]=-1;
      else times[i]=0;
      tot[i]=0;
    }
    rep(i,0,q){
      int l=queries[i][0];
      if(type[i]=="query"){
	lld ans=tot[l];
	if(times[l]!=-1){
	  ans+=i+1-times[l];
	}
	cout<<ans<<endl;
      }else{
	if(times[l]==-1){
	  times[l]=i+1;
	}else{
	  tot[l]+=i+1-times[l];
	  times[l]=-1;
	}
      }
    }
    return 0;
  }
  ST *S=new ST();
  S->build(0,n-1,1);
  rep(i,0,n){
    if(state[i]=='1')S->update(0,n-1,1,i,0);
  }
  //S->print(0,n-1,1);
  rep(i,0,q){
    if(type[i]=="toggle"){
      S->update(0,n-1,1,queries[i][0],i+1);
    }else{
      int q=(S->query(0,n-1,1,queries[i][0],queries[i][1]).second-i-1)*S->query(0,n-1,1,queries[i][0],queries[i][1]).first;
      cout<<q<<endl;
      //cout<<S->query(0,n-1,1,queries[i][0],queries[i][1]).first<<" "<<S->query(0,n-1,1,queries[i][0],queries[i][1]).second<<endl;
    }
    //S->print(0,n-1,1);
  }
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 3 ms 376 KB Output is correct
7 Correct 3 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 722 ms 13000 KB Output is correct
2 Correct 747 ms 16436 KB Output is correct
3 Correct 784 ms 17020 KB Output is correct
4 Correct 873 ms 22984 KB Output is correct
5 Correct 966 ms 23488 KB Output is correct
6 Correct 770 ms 22788 KB Output is correct
7 Correct 1346 ms 23796 KB Output is correct
8 Correct 1347 ms 25052 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 19192 KB Output is correct
2 Correct 20 ms 19192 KB Output is correct
3 Correct 21 ms 19192 KB Output is correct
4 Correct 22 ms 19192 KB Output is correct
5 Correct 519 ms 31448 KB Output is correct
6 Correct 894 ms 31548 KB Output is correct
7 Correct 1275 ms 31628 KB Output is correct
8 Correct 1706 ms 33324 KB Output is correct
9 Correct 1006 ms 29464 KB Output is correct
10 Correct 1089 ms 30588 KB Output is correct
11 Correct 1096 ms 30684 KB Output is correct
12 Correct 1665 ms 32124 KB Output is correct
13 Correct 1879 ms 33388 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 19192 KB Output is correct
2 Incorrect 21 ms 19192 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 3 ms 376 KB Output is correct
7 Correct 3 ms 376 KB Output is correct
8 Correct 722 ms 13000 KB Output is correct
9 Correct 747 ms 16436 KB Output is correct
10 Correct 784 ms 17020 KB Output is correct
11 Correct 873 ms 22984 KB Output is correct
12 Correct 966 ms 23488 KB Output is correct
13 Correct 770 ms 22788 KB Output is correct
14 Correct 1346 ms 23796 KB Output is correct
15 Correct 1347 ms 25052 KB Output is correct
16 Correct 19 ms 19192 KB Output is correct
17 Correct 20 ms 19192 KB Output is correct
18 Correct 21 ms 19192 KB Output is correct
19 Correct 22 ms 19192 KB Output is correct
20 Correct 519 ms 31448 KB Output is correct
21 Correct 894 ms 31548 KB Output is correct
22 Correct 1275 ms 31628 KB Output is correct
23 Correct 1706 ms 33324 KB Output is correct
24 Correct 1006 ms 29464 KB Output is correct
25 Correct 1089 ms 30588 KB Output is correct
26 Correct 1096 ms 30684 KB Output is correct
27 Correct 1665 ms 32124 KB Output is correct
28 Correct 1879 ms 33388 KB Output is correct
29 Correct 22 ms 19192 KB Output is correct
30 Incorrect 21 ms 19192 KB Output isn't correct
31 Halted 0 ms 0 KB -