답안 #1095191

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1095191 2024-10-01T14:08:53 Z 0pt1mus23 Janjetina (COCI21_janjetina) C++14
35 / 110
262 ms 5412 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define endl '\n'
#define ins insert
#define pb push_back
#define putr(x) cout<<x<<endl;return;
#define all(x) x.begin(),x.end()
#define _ << " " <<  
const int   mod = 1e9+7 ,
            sze= 1e5 +23 ,
            inf = INT_MAX ,
            L = 31 ;

int arr[sze];
int ans=0;
int T[sze +23];
int k;
vector<pair<int,int>> event;

void upd(int node,int x){
    for(++node;node<=sze;node += (node & -node)){
        T[node]+=x;
    }
}
int qry(int node){
    int sum=0;
    for(++node;node>0;node -= (node & -node)){
        sum+=T[node];
    }
    return sum;
}

void kullan(int vur){
    sort(all(event));
    for(auto v:event){
        ans+=vur * qry(v.first - v.second - k);
        upd(v.second,1);
    }
    for(auto v:event){
        upd(v.second,-1);
    }

    event.clear();
}
void fener(int l,int r){
    if(l>=r){
        return;
    }
    int mx = 0;
    int mid = (l+r)/2;
    fener(l,mid);
    fener(mid+1,r);
    for(int i = mid;i>=l;i--){
        event.pb({mx,mid - i});
        mx=max(mx,arr[i-1]);
    }
    mx=0;
    for(int i=mid;i<r;i++){
        mx=max(mx,arr[i]);
        event.pb({mx,i - mid +1});
    }
    kullan(1);
    mx =0;
    for(int i =mid;i>=l;i--){
        event.pb({mx, mid  - i});
        mx=max(mx,arr[i-1]);
    }
    kullan(-1);
    mx=0;
    for(int i = mid;i<r;i++){
        mx=max(mx,arr[i]);
        event.pb({mx, i - mid+1});
    }
    kullan(-1);
}   

void opt1z(){
    int n;
    cin>>n>>k;
    for(int i=1;i<n;i++){
        int x,y,w;
        cin>>x>>y>>w;
        arr[i]=w;
    }
    fener(1,n);
    cout<<ans*2LL<<endl;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
 
    int tt = 1;
    // cin>>tt;
    while(tt--){
        opt1z();
    }
 
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Correct 1 ms 532 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 2 ms 344 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Incorrect 2 ms 468 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Correct 19 ms 1008 KB Output is correct
6 Correct 115 ms 2768 KB Output is correct
7 Correct 219 ms 4816 KB Output is correct
8 Correct 262 ms 5412 KB Output is correct
9 Correct 205 ms 4860 KB Output is correct
10 Correct 262 ms 5220 KB Output is correct
11 Correct 220 ms 4824 KB Output is correct
12 Correct 236 ms 5248 KB Output is correct
13 Correct 211 ms 4940 KB Output is correct
14 Correct 255 ms 5296 KB Output is correct
15 Correct 253 ms 5068 KB Output is correct
16 Correct 259 ms 5320 KB Output is correct
17 Correct 251 ms 5140 KB Output is correct
18 Correct 248 ms 5176 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Correct 1 ms 532 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 2 ms 344 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Incorrect 2 ms 468 KB Output isn't correct
11 Halted 0 ms 0 KB -