1069

s.y.
xhxhxxh_

optimjie

LiSymbol
zhyou
AXax020913

77777777777

AcWing2AK
llllll_6

etaf

10小时前
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 100010;
int a[N],s[N];

void insert(int l,int r,int c){//左右相互抵消使得l至r全+c
s[l] += c;
s[r + 1] -= c;
}

int main()
{
int n,m;
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i ++ ){
scanf("%d",&a[i]);
insert(i,i,a[i]);
}

while (m -- ){
int l,r,c;
cin>>l>>r>>c;
insert(l,r,c);//插入
}
for (int i = 1; i <= n; i ++ )s[i] += s[i - 1];//前缀和
for (int i = 1; i <= n; i ++ )printf("%d ",s[i]);
return 0;
}


1天前

## 复盘

#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;

const int N = 1010;
int g[N][N],s[N][N];

int main()
{
int n,m,q;
cin>>n>>m>>q;
for (int i = 1; i <= n; i ++ )
for(int j = 1; j <= m;j++ )
cin>>g[i][j];

for (int i = 1; i <= n; i ++ )
for(int j = 1; j <= m;j++ )
s[i][j] = s[i][j - 1] + s[i - 1][j] - s[i - 1][j - 1] + g[i][j];

while(q--){
int x1,y1,x2,y2;
cin>>x1>>y1>>x2>>y2;
int res = s[x2][y2] - s[x2][y1 - 1] - s[x1 - 1][y2] + s[x1 -1][y1 -1];
cout<<res<<endl;
}
return 0;
}


1天前
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 100010;
int a[N],s[N];
int main()
{
int n,m;
cin>>n>>m;
for(int i = 1; i <= n;i++)cin>>a[i];
for(int i = 1; i <= n;i++) s[i] += s[i]+s[i - 1]+a[i];

while(m--){
int l,r;
cin>>l>>r;
cout<<s[r] - s[l - 1]<<endl;
}
}


1天前
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int remainder = 0;
vector<int> division(vector<int>& a,int b){
vector<int> c,d;
int t = 0;
for(int i = a.size() - 1;i >= 0 ;i--){
t = t*10+a[i];
c.push_back(t/b);
t = t - b*(t/b);
}
if(t)remainder = t;
reverse(c.begin(),c.end());
while(c.size()>1 && c.back()==0)c.pop_back();
return c;
}
int main()
{
string A;
int b;
cin>>A>>b;
vector<int>a;
for(int i = A.length() - 1 ;i >= 0 ;i--)a.push_back(A[i] - '0');
auto c = division(a,b);
for(int i = c.size() - 1 ;i >= 0 ;i--)cout<<c[i];
cout<<endl<<remainder;
return 0;
}


1天前
class Solution {
public List<Integer> getLeastNumbers_Solution(int[] input, int k) {
List<Integer> a = new ArrayList<>();
if(k==0)return a;
Queue<Integer> que = new PriorityQueue<>();
while(!que.isEmpty()){
if(a.size()==k)return a;
}
return null;
}
}


1天前

## 暴力枚举

class Solution {
public int[] findNumbersWithSum(int[] nums, int target) {
int res[] = new int[2];
for(int i = 0;i<nums.length;i++){
for(int j = 0;j<nums.length;j++){
if(nums[i]+nums[j]==target){
res[0] = nums[i];
res[1] = nums[j];
return res;
}
}
}
return res;
}
}


## Hash高级做法


class Solution {
public int[] findNumbersWithSum(int[] nums, int target) {
Scanner sc = new Scanner(System.in);
Set<Integer> hash = new HashSet<>();
for(int x : nums){
int y = target - x;
if(hash.contains(y))
return new int[]{x,y};
}
return null;
}
}


1天前
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
for(int i = 0; i < n;i++){
String op = sc.next();
if("push".equals(op)){
int x = sc.nextInt();
}
else if("pop".equals(op)){
que.remove();
}
else if("empty".equals(op)){
if(que.isEmpty()){
System.out.println("YES");
}
else{
System.out.println("NO");
}
}
else{
System.out.println(que.peek());
}
}
}
}


1天前
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
Stack<Integer> stack = new Stack<Integer>();
int n = sc.nextInt();
for (int i = 0; i < n;i++){
String s = sc.next();
if("push".equals(s)){
int x = sc.nextInt();
stack.push(x);
}
else if("query".equals(s)&&!stack.empty()){
System.out.println(stack.peek());
}
else if("pop".equals(s)&&!stack.empty()){
stack.pop();
}
else {
if(stack.empty()){
System.out.println("YES");
}
else {
System.out.println("NO");
}
}
}
}
}


2天前

## 数组做法

import java.util.*;
public class Main{
public static int N = 100010;
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int a[] = new int[n];
float d[] = new float[N];
String s[] = new String[N];
for(int i = 0;i < n;i++){
a[i] = sc.nextInt();
d[a[i]] = sc.nextFloat();
s[a[i]] = sc.next();
}
Arrays.sort(a);
for(int i = 0;i < n;i++){
System.out.printf("%d %.2f %s\n",a[i],d[a[i]],s[a[i]]);
}
}
}


## 类做法

import java.util.*;
class Data implements Comparable<Data>{
int x;
double y;
String s;
public Data(int x,double y,String s){
this.x = x;
this.y = y;
this.s = s;
}
public int compareTo(Data t){
return this.x - t.x;
}
}
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
Data a[] = new Data[n];
for(int i = 0;i < n;i++){
a[i] = new Data(sc.nextInt(),sc.nextDouble(),sc.next());
}
Arrays.sort(a);
for(int i = 0;i < n;i++){
System.out.printf("%d %.2f %s\n",a[i].x,a[i].y,a[i].s);
}
}
}


2天前

## 状态数组做法

class Solution {
int st[] = new int[200];
ListNode n = null;
while(h != null){
if(st[h.val]==1||st[h.val]==2){
st[h.val]=2;
n.next= h.next;
h = h.next;
}
else {
st[h.val] = 1;
n = h;
h = h.next;
}
}
while(h.next != null){
}
else if(st[h.next.val]==2){
h.next = h.next.next;
}
else h = h.next;
}
}
}


## 双指针

class Solution {