답안 #1006315

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1006315 2024-06-23T18:25:24 Z 0pt1mus23 Sterilizing Spray (JOI15_sterilizing) C++14
0 / 100
5000 ms 2152 KB
#pragma GCC optimize("O3", "inline")
#include <bits/stdc++.h>
using namespace std;
#define ins insert
#define pb push_back
// #define int long long int
#define pii pair<int, int>
#define endl '\n'
#define drop(x) cout<<(x)<<endl; return;
#define all(x) x.begin(),x.end()
const int mod = 1e9 +7, sze = 4*100000, inf = 2e18, prime = 23;
int T[sze];
vector<int> arr;
void build(int node,int l,int r){
    if(l==r){
        T[node]=arr[l];
        return ;
    }
    int mid = (l+r)/2;
    build((node<<1),l,mid);
    build((node<<1)|1,mid+1,r);
    T[node]= T[(node<<1)] + T[(node<<1)|1];
}
void upd(int node,int idx,int l,int r,int v){
    if(l==r){
        T[node]=v;
        return;
    }
    int mid = l+r>>1;
    if(idx<=mid){
        upd((node<<1),idx,l,mid,v);
    }
    else{
        upd((node<<1)|1,idx,mid+1,r,v);
    }
    T[node]= T[(node<<1)] + T[(node<<1)|1];
 
}
 
void sil(int node,int l,int r,int lx,int rx,int v){
    // cout<<T[node]<<endl;
    if(lx>r || rx<l || T[node]==0){
        return;
    }
    if(lx==rx){
        // cout<<T[node]<<" silirem"<<endl;
        T[node]/=v;
        return;
    }
    int mid = lx+rx>>1;
    sil((node<<1),l,r,lx,mid,v);
    sil((node<<1) +1,l,r,mid+1,rx,v);
    T[node]= T[(node<<1)] + T[(node<<1)|1];
}
int qry(int node,int l,int r,int lx,int rx){
    if(l>rx || lx>r || T[node]==0){
        return 0;
    }
    if(lx>=l && rx<=r){
        return T[node];
    }
    int mid = lx+rx>>1;
    int left = qry((node<<1),l,r,lx,mid);
    int right = qry((node<<1)|1,l,r,mid+1,rx);
    return left+right;
}
 
void mal(){
    int n,m,k;
    cin>>n>>m>>k;
    
    for(int i=0;i<n;i++){
        int x;cin>>x;
        arr.pb(x);
        // if(x){
        //     upd(1,i,0,n-1,x);
        // }
    }
    build(1,0,n-1);
    while(m--){
        int op;cin>>op;
        if(op==1){
            int idx,v;cin>>idx>>v;
            upd(1,--idx,0,n-1,v);
        }
        else if(op==2){
            int l,r;cin>>l>>r;
            --l;--r;
            sil(1,l,r,0,n-1,k);
            // cout<<"sildim: "<<T[1]<<endl;
        }
        else if(op==3){
            int l,r;cin>>l>>r;
            --l;--r;
            cout<<qry(1,l,r,0,n-1)<<endl;
        }
 
    }
 
}  
 
 
signed main() {
    cin.tie(0)->sync_with_stdio(0);
    int tt = 1;
    // cin>>tt;
    
    while(tt--){
        mal();        
    }
}

Compilation message

sterilizing.cpp:11:47: warning: overflow in conversion from 'double' to 'int' changes value from '2.0e+18' to '2147483647' [-Woverflow]
   11 | const int mod = 1e9 +7, sze = 4*100000, inf = 2e18, prime = 23;
      |                                               ^~~~
sterilizing.cpp: In function 'void upd(int, int, int, int, int)':
sterilizing.cpp:29:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   29 |     int mid = l+r>>1;
      |               ~^~
sterilizing.cpp: In function 'void sil(int, int, int, int, int, int)':
sterilizing.cpp:50:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   50 |     int mid = lx+rx>>1;
      |               ~~^~~
sterilizing.cpp: In function 'int qry(int, int, int, int, int)':
sterilizing.cpp:62:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   62 |     int mid = lx+rx>>1;
      |               ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1782 ms 1564 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 608 KB Output is correct
2 Correct 5 ms 1244 KB Output is correct
3 Correct 8 ms 1296 KB Output is correct
4 Correct 20 ms 860 KB Output is correct
5 Correct 24 ms 2008 KB Output is correct
6 Correct 40 ms 2060 KB Output is correct
7 Execution timed out 5071 ms 2152 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 34 ms 1500 KB Output isn't correct
2 Halted 0 ms 0 KB -