Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
EatRawLife committed Sep 4, 2024
2 parents 3bd03be + 4df7bdd commit b3cf074
Show file tree
Hide file tree
Showing 5 changed files with 207 additions and 0 deletions.
27 changes: 27 additions & 0 deletions 강정우/Boj27172.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include <iostream>
#include <vector>
using namespace std;
vector<int> numbers;
int score[1000006];
int card[1000006];
int main(){
int n;
cin >> n;
for (int i = 0; i < n; i++) {
int t;
cin >> t;
numbers.push_back(t);
card[t] = 1;
}
for (int i = 0; i < n; i++){
for (int j = numbers[i] * 2; j < 1000001; j += numbers[i]){
if (card[j] == 1){
score[numbers[i]]++;
score[j]--;
}
}
}
for (int i = 0; i < n; i++)
cout<<score[numbers[i]]<<" ";
return 0;
}
28 changes: 28 additions & 0 deletions 김규현/B10773.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import java.io.*;
import java.util.*;

public class B10773 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

int n = Integer.parseInt(br.readLine());

Stack<Integer> stack = new Stack<>();

for (int i = 0; i < n; i++) {
int temp = Integer.parseInt(br.readLine());
if(temp !=0){
stack.push(temp);
}
else{
stack.pop();
}
}
int stackSize = stack.size();
int sum = 0;
for(int i = 0; i < stackSize; i++){
sum += stack.pop();
}
System.out.println(sum);
}
}
48 changes: 48 additions & 0 deletions 김우솔/backjoon_25633.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package Dp;

import java.io.*;
import java.util.*;

public class backjoon_25633 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));

int a = Integer.parseInt(br.readLine());
int[] arr = new int[a];
int[] sum = new int[a];
int[] dp = new int[a];

StringTokenizer st = new StringTokenizer(br.readLine());
for (int i = 0; i < a; i++) {
arr[i] = Integer.parseInt(st.nextToken());
}

sum[0] = arr[0];
dp[0] = 1;

for (int i = 1; i < arr.length; i++) {
for (int j = i - 1; j >= 0; j--) {
if (sum[j] >= arr[i]) { //dp가 바뀔 경우에만 바꿔줌
if (dp[j] > dp[i]) {
sum[i] = arr[i] + sum[j];
dp[i] = dp[j];
}
}
}
if (dp[i] == 0) { //한번도 큰 값을 못 찾을 때
sum[i] = arr[i];
}
dp[i]++;
}

int max = 1;
for (int i = 0; i < dp.length; i++) {
max = Math.max(dp[i], max);
}

bw.write(max + "\n");
bw.flush();
bw.close();
}
}
38 changes: 38 additions & 0 deletions 조민영/1806 부분합.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import java.io.*;
import java.util.*;

public class g1806 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

StringTokenizer st = new StringTokenizer(br.readLine());

int n = Integer.parseInt(st.nextToken());
int s = Integer.parseInt(st.nextToken());

int[] arr = new int[n];
st = new StringTokenizer(br.readLine());

for ( int i = 0 ; i < n ; i++ )
arr[i] = Integer.parseInt(st.nextToken());

int start = 0;
int end = 0;
int sum = 0;
int min = Integer.MAX_VALUE;
boolean exist = false;

while ( true ) {
if ( sum >= s ) {
min = Math.min(min, end-start);
sum -= arr[start++];
exist = true;
} else if ( end == n )
break;
else
sum += arr[end++];
}

System.out.println(exist ? min : 0 );
}
}
66 changes: 66 additions & 0 deletions 조서현/24915_센터가 돋보여야 해.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#include <bits/stdc++.h>

using namespace std;

constexpr int sz = 333'333, sgsz = 1 << (33 - __builtin_clz(sz)), dummy = 1e9;

struct node
{
int mn, mx, mnmx, mxmn, res;
node(int v) {
mn = mx = v;
mnmx = mxmn = res = -dummy;
}
node() : node(0){
mn = dummy;
mx = -dummy;
}
node operator+(const node& o) const {
node ret;
ret.mn = min(mn, o.mn);
ret.mx = max(mx, o.mx);
ret.mnmx = max({mnmx, o.mnmx, o.mx - mn});
ret.mxmn = max({mxmn, o.mxmn, mx - o.mn});
ret.res = max({res, o.res, mnmx - o.mn, o.mxmn - mn});
return ret;
}
} tree[sgsz];

int arr[sz], loc[sz];

node& init(int s, int e, int i = 1){
if (s == e){
loc[s] = i;
return tree[i] = node(arr[s]);
}
int m = s + e >> 1;
return tree[i] = init(s, m, i << 1) + init(m + 1, e, i << 1 | 1);
}

void update(int idx, int v){
int i = loc[idx];
tree[i] = node(v);
while (i >>= 1)
tree[i] = tree[i << 1] + tree[i << 1 | 1];
}

node query(int s, int e, int l, int r, int i = 1){
if (r < s || e < l) return node();
if (l <= s && e <= r) return tree[i];
int m = s + e >> 1;
return query(s, m, l, r, i << 1) + query(m + 1, e, l, r, i << 1 | 1);
}

int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

int n, q; cin >> n >> q;
for (int i = 0; i < n; ++i) cin >> arr[i];
init(0, n - 1);

while (q--){
int a, b, c; cin >> a >> b >> c;
if (a == 1) update(b - 1, c);
else cout << query(0, n - 1, b - 1, c - 1).res << '\n';
}
}

0 comments on commit b3cf074

Please sign in to comment.