답안 #704667

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
704667 2023-03-02T15:17:28 Z BidoTeima Sterilizing Spray (JOI15_sterilizing) C++17
0 / 100
9 ms 6228 KB
/*
ID: BidoTeima
LANG: C++11
TASK:
*/
#include <bits/stdc++.h> 
using namespace std;
using ll = long long;
void moo(string filename);
void ACPLS(string str = "")
{
    if(str=="NOF")return;
    if(str.size() && str != "IIOT")
        moo(str);
    else if(str != "IIOT"){
#ifndef ONLINE_JUDGE
        freopen("output.txt", "w", stdout);
        freopen("input.txt", "r", stdin);
#endif
    }
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
void moo(string fileName){
    freopen((fileName+".in").c_str(),"r",stdin);
    freopen((fileName+".out").c_str(),"w",stdout);
}
#define tc         \
    int tttttt/*,subtask*/;    \
    cin >> tttttt/* >> subtask*/; \
    while (tttttt--)/*end
*/
constexpr int N = 1e5 + 3;
ll seg[8 * N], lazy[8 * N];
ll a[N];
void propagate(int node){
    assert(lazy[node]);
    seg[node] /= lazy[node];
    lazy[2 * node + 1] = lazy[2 * node + 2] = lazy[node];
    lazy[node] = 1;
}
void build(int l, int r, int node){
    lazy[node] = 1;
    if(l == r){
        seg[node] = a[l];
        return;
    }
    int mid = (l + r) >> 1;
    build(l, mid, 2 * node + 1);
    build(mid+1, r, 2 * node + 2);
    seg[node] = seg[2 * node + 1] + seg[2 * node + 2];
}
void upd(int l, int r, int idx, ll value, int node){
    propagate(node);
    if(idx<l||idx>r)
        return;
    if(l == r){
        seg[node] = value;
        return;
    }
    int mid = (l + r) >> 1;
    upd(l, mid, idx, value, 2 * node + 1);
    upd(mid + 1, r, idx, value, 2 * node + 2);
    seg[node] = seg[2 * node + 1] + seg[2 * node + 2];
}
int query(int l, int r, int ql, int qr, int node){
    propagate(node);
    if(l > r)
        return 0;
    if(l > qr || r < ql)
        return 0;
    if(ql <= l && r <= qr)
        return seg[node];
    int mid = (l + r) >> 1;
    return query(l, mid, ql, qr, 2 * node + 1) + 
            query(mid + 1, r, ql, qr, 2 * node + 2);
}
void lazy_upd(int l, int r, int ql, int qr, ll value, int node){
    propagate(node);
    if(l > qr || r < ql)
        return;
    if(ql <= l && qr <= r){ 
        if(lazy[node] < 1e18/value){
            lazy[node] *= value;  
            propagate(node);
        } 
        return;
    }
    int mid = (l + r) >> 1;
    lazy_upd(l, mid, ql, qr, value, 2 * node + 1);
    lazy_upd(mid + 1, r, ql, qr, value, 2 * node + 2);
    seg[node] = seg[2 * node + 1] + seg[2 * node + 2];
}
int main()
{ 
    ACPLS("IIOT");  
    int n,q,k;
    cin>>n>>q>>k;
    for(int i = 0; i < n; i++)
        cin>>a[i];
    build(0, n - 1, 0);
    while(q--){
        int S;
        cin>>S;
        int T, U;
        cin>>T>>U;
        if(S == 1){
            int a=T,b=U;
            upd(0, n - 1, a - 1, b, 0);
        }
        if(S == 2){
            int l, r; 
            l=T,r=U;
            --l, --r;
            lazy_upd(0, n - 1, l, r, k, 0);
        }
        if(S == 3){
            int l, r;
            l=T,r=U;
            --l, --r;
            cout<<query(0, n - 1, l, r, 0)<<'\n';
        }
    } 
}

Compilation message

sterilizing.cpp: In function 'void ACPLS(std::string)':
sterilizing.cpp:17:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |         freopen("output.txt", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
sterilizing.cpp:18:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |         freopen("input.txt", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
sterilizing.cpp: In function 'void moo(std::string)':
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((fileName+".in").c_str(),"r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sterilizing.cpp:27:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |     freopen((fileName+".out").c_str(),"w",stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 724 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 9 ms 6124 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 3 ms 1236 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 9 ms 6228 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -