Submission #1257245

#TimeUsernameProblemLanguageResultExecution timeMemory
1257245efeg새로운 문제 (POI11_met)C++20
0 / 100
23 ms48708 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define F first
#define S second
#define pb push_back
#define endl '\n'
#define all(v) v.begin(),v.end()
#define gcd(a,b) __gcd(a,b)
#define mt make_tuple
#define pqueue priority_queue

typedef pair<int,int> ii;
typedef tuple<int,int,int> iii;
typedef tuple<int,int,int,int> iiii;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<iii> viii;
typedef set<int> si;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<si> vsi;
typedef vector<vb> vvb;
typedef vector<vc> vvc;

struct SegmentTree{
    vi tree,lazy; int n; 
    SegmentTree (int _n){
        n = _n;
        tree.assign(4 * n + 10,0); 
        lazy.assign(4 * n + 10,0); 
    }

    void push(int node,int s,int e){
        if (lazy[node] == 0) return;
        tree[node] += lazy[node] * (e - s + 1); 
        if (s < e){
            lazy[node*2] += lazy[node];
            lazy[node*2+1] += lazy[node]; 
        } 
        lazy[node] = 0; 
    }

    int query(int node,int s,int e,int x){
        push(node,s,e); 
        if (s > e || e < x || x < s) return 0; 
        if (s == e && s == x) return tree[node]; 
        int m = (s+e) / 2; 
        int a = query(node*2,s,m,x); 
        int b = query(node*2+1,m+1,e,x); 
        return (a+b); 
    }

    void update(int node,int s,int e,int l,int r,int val){
        push(node,s,e); 
        if (s > e || r < s || e < l) return;
        if (l <= s && e <= r){
            lazy[node] += val; 
            push(node,s,e); 
            return; 
        }
        int m = (s+e) / 2;
        update(node*2,s,m,l,r,val);
        update(node*2+1,m+1,e,l,r,val); 
        tree[node] = tree[node*2] + tree[node*2+1]; 
    }
};

int32_t main(){
    ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
    #ifndef ONLINE_JUDGE
        freopen("output.txt","w",stdout);
        freopen("input.txt","r",stdin);
        clock_t stime = clock();
    #endif

    int n,m,k; 
    cin >> n >> m; 
    vi sec(m,0),gerekli(n,0);
    vvi devlet(n,vi()); 
    
    for (int i = 0; i < m; i++){
        cin >> sec[i]; sec[i]--;
        devlet[sec[i]].pb(i); 
    }
    for (int i = 0; i < n; i++) cin >> gerekli[i]; 
    cin >> k;
    viii queries(k+1);
    for (int i = 1; i <= k; i++){
        int l,r,x; cin >> l >> r >> x;
        queries[i] = make_tuple(l-1,r-1,x); 
    } 
    vi left(n,1),right(n,k+1); 

    for (int i = 0; i < ceil(log2(k+1)); i++){
        SegmentTree tree(n); 
        vvi check(k+10,vi());
        for (int i = 0; i < n; i++){
            if (left[i] < right[i]){
                int mid = (left[i] + right[i]) / 2;
                check[mid].pb(i); 

            }
        }
        for (int j = 1; j <= k; j++){
            int a,b,val; tie(a,b,val) = queries[j]; 
            if (a <= b) tree.update(1,0,m-1,a,b,val); 
            if (a > b){
                tree.update(1,0,m-1,a,m-1,val);
                tree.update(1,0,m-1,0,b,val); 
            }
            
            for (auto state : check[j]){
                int sum = 0; 
                for (auto s : devlet[state]){
                    sum += tree.query(1,0,m-1,s); 
                }
                if (sum >= gerekli[state]) right[state] = j;
                else left[state] = j + 1; 

            }
        }
    }

    for (int i = 0; i < n; i++){
        if (left[i] == k+1) cout << "NIE" << endl; 
        else cout << left[i] << endl; 
    }
    
    return 0;
}

Compilation message (stderr)

met.cpp: In function 'int32_t main()':
met.cpp:75:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   75 |         freopen("output.txt","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
met.cpp:76:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   76 |         freopen("input.txt","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...