답안 #952528

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
952528 2024-03-24T07:35:26 Z guymmk Sterilizing Spray (JOI15_sterilizing) C++14
0 / 100
8 ms 3932 KB
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
#define int long long
#define ll long long
#define endl "\n"
#define vi vector<int>
#define vpii vector<pair<int,int> >
#define umap unordered_map
#define uset unordered_set
#define mk make_pair
#define pb push_back
//#define pop pop_back
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define read(x) for (auto& zu: (x)) cin >> zu;
#define F first
#define S second
#define mustawa ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)
#define pii pair<int,int>
#define mishari main
const int inf=1e9+7;
void fa(bool ok){ cout << (ok ? "Yes": "No") << "\n";}
void usaco(string s) {
    freopen((s + ".in").c_str(), "r", stdin);
    freopen((s + ".out").c_str(), "w", stdout);
}
struct Segtree{
    int off;
    vi tree;
    Segtree(int n){
        off= 1<<(int)ceil(log2(n));
        tree.resize(off*2);
    }
    int _query(int l, int r, int cl, int cr, int i){
        if(cl>r||cr<l)return 0;
        else if(cl>=l&&cr<=r){
            return tree[i];
        }int md=(cl+cr)/2;
        return _query(l, r, cl, md, i * 2) + _query(l, r, md + 1, cr, i * 2 + 1);
    }int query(int l,int r){
        return _query(l,r,0,off - 1, 1);
    }
    void update(int i,int x){
        i+=off;
        tree[i]=x;
        while(i/=2){
            tree[i]=tree[i*2]+tree[i*2+1];
        }
    }

};
void solve() {
    int n,q,k;
    cin>>n>>q>>k;
    int a[n];
    Segtree seg=Segtree(n);
    for(int i=0;i<n;i++)cin>>a[i];
    while(q--){
        int g,l,r;
        l--;
        cin>>g;
        if(g==1){
            seg.update(l,r);
        }else if(g==2){
//            for(int i=l;i<r;i++){
//                a[i]/=k;
//            }
        }else{
            cout<<seg.query(l,r-1)<<endl;
        }
    }
}

signed mishari() {
    mustawa;
    //usaco("");
    int t = 1;
    //cin>>t;
    while (t--)solve();
}

Compilation message

sterilizing.cpp: In function 'void usaco(std::string)':
sterilizing.cpp:25:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |     freopen((s + ".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sterilizing.cpp:26:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |     freopen((s + ".out").c_str(), "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sterilizing.cpp: In function 'void solve()':
sterilizing.cpp:46:16: warning: 'r' may be used uninitialized in this function [-Wmaybe-uninitialized]
   46 |         tree[i]=x;
sterilizing.cpp:60:17: note: 'r' was declared here
   60 |         int g,l,r;
      |                 ^
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 8 ms 3932 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 860 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 6 ms 3932 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -